Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Solution {
- public int[] solution;
- public int[] twoSum(int[] nums, int target) {
- HashMap hashmap = new HashMap();
- for(int i=0; i < nums.length; i++){
- hashmap.put(nums[i], i);
- }
- for(int i=0; i < nums.length; i++){
- int another = target - nums[i];
- if(hashmap.containsKey(another) && (int)hashmap.get(another) !=i){
- int another_index;
- another_index = (int)hashmap.get(another);
- solution = new int[2];
- solution[0] = i;
- solution [1] = another_index;
- return solution;
- }
- }
- return nums;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement