[ 命名建議 ] LeetCode 167. Two Sum II - Input array is sorted #109
Answered
by
twy30
LPenny-github
asked this question in
Q&A
-
|
LeetCode: 線上教材: 再麻煩 @twy30 給予命名建議 orz 感激不盡 namespace Sandbox
{
public class TwoSum2
{
public int[] TwoSum(int[] numbers, int target)
{
int[] input = numbers;
int firstPointer = 0, secondPointer = input.Length -1;
while (firstPointer != secondPointer )
{
int difference = target - input[firstPointer];
if (difference == input[secondPointer])
{
return new int[]{firstPointer+1, secondPointer+1};
}
else if (difference > input[secondPointer])
{
++firstPointer;
}
else if (difference < input[secondPointer])
{
--secondPointer;
}
}
return new int[]{};
}
}
} |
Beta Was this translation helpful? Give feedback.
Answered by
twy30
Jan 2, 2021
Replies: 1 comment 1 reply
-
|
你好 😊 int firstPointer = 0, secondPointer = input.Length -1;這裡的 "pointer" 比較偏向 C/C++ 的術語。 就這個題目來說,可以考慮以下的命名方式:
|
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
你好 😊
這裡的 "pointer" 比較偏向 C/C++ 的術語。
就這個題目來說,可以考慮以下的命名方式:
firstIndex,secondIndexindex1,index2index1,index2是 ok 的 😊