File tree Expand file tree Collapse file tree 2 files changed +7
-4
lines changed
Expand file tree Collapse file tree 2 files changed +7
-4
lines changed Original file line number Diff line number Diff line change 44class Solution {
55 public boolean containsDuplicate (int [] nums ) {
66 Set <Integer > set = new HashSet ();
7+
78 for (int n : nums ){
89 if (set .contains (n )){
910 return true ;
1011 }
1112 set .add (n );
1213 }
14+
1315 return false ;
1416 }
1517}
Original file line number Diff line number Diff line change 44class Solution {
55 public int [] twoSum (int [] nums , int target ) {
66 Map <Integer , Integer > map = new HashMap <>();
7- for (int i = 0 ; i < nums .length ; i ++){
7+
8+ for (int i = 0 ; i < nums .length ; i ++) {
89 map .put (nums [i ], i );
910 }
1011
11- for (int i = 0 ; i < nums .length ; i ++){
12- if (map .containsKey (target - nums [i ])
13- && map .get (target - nums [i ]) != i ){
12+ for (int i = 0 ; i < nums .length ; i ++) {
13+ if (map .containsKey (target - nums [i ]) && map .get (target - nums [i ]) != i ) {
1414 int j = map .get (target - nums [i ]);
1515 return new int []{i , j };
1616 }
1717 }
18+
1819 return null ;
1920 }
2021}
You can’t perform that action at this time.
0 commit comments