Skip to content
Merged
Show file tree
Hide file tree
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
12 changes: 12 additions & 0 deletions .github/copilot-instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
## 役割
あなたは競技プログラミング(LeetCode、AtCoder等)のコード評価者です。提出されたコードを10点満点で評価し、詳細なフィードバックを提供してください。

## 言語指定
**必ず日本語でレビューを提供してください。** コード例やコメントは元の言語(TypeScript、Python等)のままでも構いませんが、評価コメント、説明、フィードバックは全て日本語で記述してください。

## 評価基準

### 点数配分(10点満点)
Expand Down Expand Up @@ -133,6 +136,12 @@

## 評価時の注意点

### 言語要件
- **評価コメント**: 必ず日本語で記述
- **説明文**: 全て日本語で提供
- **フィードバック**: 日本語で建設的に
- **コード例**: 元の言語(TypeScript、Python等)のまま可

### 必ず含める要素
1. **具体的なコード例**: 問題のある部分と改善案を両方示す
2. **テストケース**: 実際の入力・出力例
Expand Down Expand Up @@ -182,3 +191,6 @@
```

この指示に従って、提出されたコードを詳細に評価し、学習者の成長をサポートしてください。

## 🚨 最終確認
**重要**: 全ての評価コメント、説明、フィードバックは必ず日本語で提供してください。コード例のみ元の言語(TypeScript、Python等)のままで構いません。
20 changes: 20 additions & 0 deletions src/leetcode/27_remove-element/20251024.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export function removeElement(nums: number[], val: number): number {
const removedNum = -1;
let i = nums.length - 1;
let j = nums.length - 1;

while (i >= 0) {
if (nums[i] === val) {
if (i === j) {
nums[j] = removedNum;
} else {
nums[i] = nums[j];
nums[j] = removedNum;
}
Comment on lines +8 to +13
Copy link

Copilot AI Oct 23, 2025

Choose a reason for hiding this comment

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

The conditional check i === j is unnecessary. When i equals j, nums[i] = nums[j] is effectively a no-op assignment of the same value, and the assignment nums[j] = removedNum can be done unconditionally. This logic can be simplified to remove the conditional branch.

Suggested change
if (i === j) {
nums[j] = removedNum;
} else {
nums[i] = nums[j];
nums[j] = removedNum;
}
nums[i] = nums[j];
nums[j] = removedNum;

Copilot uses AI. Check for mistakes.
j--;
}
i--;
}

return j + 1;
};
Comment on lines +2 to +20
Copy link

Copilot AI Oct 23, 2025

Choose a reason for hiding this comment

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

The sentinel value -1 may conflict with actual array values. LeetCode's problem constraint allows values from 0 to 50, but negative numbers are valid in general arrays. The problem doesn't require marking removed elements—simply moving them to the end is sufficient.

Suggested change
const removedNum = -1;
let i = nums.length - 1;
let j = nums.length - 1;
while (i >= 0) {
if (nums[i] === val) {
if (i === j) {
nums[j] = removedNum;
} else {
nums[i] = nums[j];
nums[j] = removedNum;
}
j--;
}
i--;
}
return j + 1;
};
let k = 0;
for (let i = 0; i < nums.length; i++) {
if (nums[i] !== val) {
nums[k] = nums[i];
k++;
}
}
return k;
}

Copilot uses AI. Check for mistakes.
Copy link

Copilot AI Oct 23, 2025

Choose a reason for hiding this comment

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

[nitpick] Remove the semicolon after the closing brace. Function declarations don't require trailing semicolons in TypeScript/JavaScript.

Suggested change
};
}

Copilot uses AI. Check for mistakes.