[ 命名建議 ] LeetCode 26. Remove Duplicates from Sorted Array #113
Answered
by
twy30
LPenny-github
asked this question in
Q&A
-
|
LeetCode: 再麻煩 @twy30 給予命名建議 orz 感激不盡 (這次因為不是頭、尾,所以我還是用 first、second 命名,如果不適用,再麻煩大大指教 😅) using System;
public int RemoveDuplicates(int[] nums)
{
int[] input = nums;
if (input.Length == 0){ return 0; }
if (input.Length == 1){ return 1; }
int firstIndex = 0;
int secondIndex = 1;
int output = 1;
while (secondIndex < input.Length)
{
if (input[firstIndex] == input[secondIndex])
{
++secondIndex;
}
else
{
++output;
++firstIndex;
input[firstIndex] = input[secondIndex];
++secondIndex;
}
}
Array.Resize(ref input, output);
return output;
} |
Beta Was this translation helpful? Give feedback.
Answered by
twy30
Jan 5, 2021
Replies: 1 comment 1 reply
-
|
你好 😊
沒問題 😊 int firstIndex = 0;
int secondIndex = 1;
int output = 1;可以參考看看以下這樣的命名
|
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
LPenny-github
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@LPenny-github
你好 😊
沒問題 😊
可以參考看看以下這樣的命名
firstIndex換成outputIndexsecondIndex的second可以換成search,comparison, 或inspectionoutput換成newLength或newArrayLength