1
class Solution {
2
public int[] twoSum(int[] nums, int target) {
3
int[] answer = new int[2];
4
// Two for loops for selecting two numbers and check sum equal to target or not
5

6
for (int i = 0; i < nums.length; i++) {
7
for (int j = i + 1; j < nums.length; j++) {
8
// j = i + 1; no need to check back elements it covers in i;
9
if (nums[i] + nums[j] == target) {
10
// Check sum == target or not
11
answer[0] = i;
12
answer[1] = j;
13
return answer;
14
}
15
}
16
}
17
return null;
18
}
19
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0