Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/leetcode/80_remove-duplicates-from-sorted-array-ii/20251029.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
func removeDuplicates(nums []int) int {
var arr []int
Copy link

Copilot AI Oct 29, 2025

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)に改善することを推奨します。

Copilot generated this review using guidance from repository custom instructions.
k := 0

for i := 0; i < len(nums) - 1; i++ {
Copy link

Copilot AI Oct 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ループがlen(nums) - 1で終了するため、配列の最後の要素が処理されません。これにより、最後の要素が結果に含まれない可能性があります。ループ条件をi < len(nums)に変更するか、ループ後に最後の要素を別途処理する必要があります。

Copilot generated this review using guidance from repository custom instructions.
if nums[i] != nums[i + 1] {
arr = []int{}
Copy link

Copilot AI Oct 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ループ内でarrを新しい空のスライスで再初期化していますが、これは以前に割り当てられたメモリを無駄にします。arr = arr[:0]を使用してスライスの長さをリセットする方が効率的です。ただし、この問題はin-placeで解くべきなので、補助配列自体を使わないアプローチが望ましいです。

Copilot generated this review using guidance from repository custom instructions.
}

arr = append(arr, nums[i])

if len(arr) > 2 {
}
Comment on lines +12 to +13
Copy link

Copilot AI Oct 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

条件分岐の中身が空です。len(arr) > 2の場合、配列に要素を追加しない処理が必要ですが、現在は何も実装されていません。この条件でarrへの追加をスキップするか、または配列の長さを制限するロジックを実装する必要があります。

Copilot generated this review using guidance from repository custom instructions.
}

return k
Copy link

Copilot AI Oct 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

変数kは初期化されているものの、ループ内で更新されていません。常に0が返されるため、関数が正しい結果を返しません。kは処理された有効な要素数を追跡し、適切にインクリメントする必要があります。

Copilot generated this review using guidance from repository custom instructions.
}
Loading