File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change
1
+ class Solution {
2
+ public boolean containsDuplicate (int [] nums ) {
3
+ Set <Integer > numbers = new HashSet <Integer >();
4
+ for (int num : nums ) {
5
+ if (numbers .contains (num )) return true ;
6
+ numbers .add (num );
7
+ }
8
+
9
+ return false ;
10
+ }
11
+ }
Original file line number Diff line number Diff line change
1
+ class Solution {
2
+ public boolean isAnagram (String s , String t ) {
3
+ if (s .length () != t .length ()) return false ;
4
+
5
+ int [] countS = new int [26 ];
6
+ int [] countT = new int [26 ];
7
+
8
+ for (int i = 0 ; i < s .length () ; i ++) {
9
+ countS [s .charAt (i ) - 'a' ]++;
10
+ countT [t .charAt (i ) - 'a' ]++;
11
+ }
12
+
13
+ for (int i = 0 ; i < 26 ; i ++) {
14
+ if (countS [i ] - countT [i ] != 0 ) return false ;
15
+ }
16
+
17
+ return true ;
18
+ }
19
+ }
You can’t perform that action at this time.
0 commit comments