Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Solution {
- // DO NOT MODIFY THE LIST. IT IS READ ONLY
- public ArrayList<Integer> twoSum(final List<Integer> A, int B) {
- Map<Integer,Integer> map = new HashMap<>();
- ArrayList<Integer> list = new ArrayList<>();
- for(int i = 0;i< A.size();i++){
- if(!map.containsKey(B-A.get(i))){
- if(!map.containsKey(A.get(i))){
- map.put(A.get(i),i);
- }
- }else{
- list.add(map.get(B-A.get(i))+1);
- list.add(i+1);
- return list;
- }
- }
- return list;
- }
- }
Add Comment
Please, Sign In to add comment