-
Notifications
You must be signed in to change notification settings - Fork 0
Add removeDuplicates function for sorted array #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| func removeDuplicates(nums []int) int { | ||
| var arr []int | ||
| k := 0 | ||
|
|
||
| for i := 0; i < len(nums) - 1; i++ { | ||
|
||
| if nums[i] != nums[i + 1] { | ||
| arr = []int{} | ||
|
||
| } | ||
|
|
||
| arr = append(arr, nums[i]) | ||
|
|
||
| if len(arr) > 2 { | ||
| } | ||
|
Comment on lines
+12
to
+13
|
||
| } | ||
|
|
||
| return k | ||
|
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
補助配列
arrを使用していますが、この問題はin-placeで解くべき問題です。LeetCode 80の要件では、追加のO(n)空間を使わずに元の配列を直接変更する必要があります。ツーポインタ手法を使用して、空間計算量をO(1)に改善することを推奨します。