Ssup2 Blog logo Ssup2 Blog

Problem

Solution 1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class Solution {
    public int[] twoSum(int[] nums, int target) {
        int i = 0, j = 0;
        
        loop:
        for (i = 0; i < nums.length; i++) {
            for (j = i + 1; j < nums.length; j++) {
                if (nums[i] + nums[j] == target) {
                   break loop; 
                }
            }
        }
        
        return new int[] {i, j};
    }
}
Solution 1