Skip to content

Commit ad70f76

Browse files
committed
inprove readability
1 parent 6532adb commit ad70f76

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

Algorithms Basics/Chapter 1. Array_String/167. Two Sum II - Input array is sorted.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,22 @@ 653. Two Sum IV - Input is a BST
55
*/
66
public class Solution {
77
public int[] TwoSum(int[] nums, int target) {
8-
int[] res = null;
9-
if (nums == null || nums.Length == 0) {
10-
return res;
8+
int[] result = null;
9+
if (nums == null || nums.Length < 2) {
10+
return result;
1111
}
1212
for (int i = 0, j = nums.Length - 1; i < j;) {
13-
var v = nums[i] + nums[j];
14-
if (v == target) {
15-
res = new int[] { i + 1, j + 1 };
13+
var sum = nums[i] + nums[j];
14+
if (sum == target) {
15+
result = new int[] { i + 1, j + 1 };
1616
break;
1717
}
18-
if (v < target) {
18+
if (sum < target) {
1919
i++;
2020
} else {
2121
j--;
2222
}
2323
}
24-
return res;
24+
return result;
2525
}
2626
}

0 commit comments

Comments
 (0)