3. Two Sum
Code
class Solution {
public int[] twoSum(int[] nums, int target) {
int[] result = new int[2];
for (int index = 0; index < nums.length; index++) {
for (int innerIndex = 0; innerIndex < nums.length; innerIndex++) {
if (index != innerIndex && (nums[index] + nums[innerIndex] == target)) {
result[0] = index;
result[1] = innerIndex;
return result;
}
}
}
return result;
}
}
Code: Using Hashmap

Last updated