File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed
Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change 1+ /**
2+ * Runtime: 2ms
3+ * Time Complexity: O(n)
4+ *
5+ * Memory: 44.56MB
6+ * Space Complexity: O(1)
7+ *
8+ * Approach: a~z μνλ²³ κ°μ λ°°μ΄μ μ¬μ©νμ¬ μ§μ μ΄λ£¨λμ§ κ²μ¬
9+ * - μνλ²³ κ°μκ° λκ°λ€λ©΄ +- νμ λ 0μ΄ λ¨
10+ */
11+ class Solution {
12+ public boolean isAnagram (String s , String t ) {
13+ if (s .length () != t .length ()) return false ;
14+
15+ int [] checkedArr = new int [26 ];
16+ for (char element : s .toCharArray ()) {
17+ int index = (int )element - 'a' ;
18+ checkedArr [index ]++;
19+ }
20+
21+ for (char element : t .toCharArray ()) {
22+ int index = (int )element - 'a' ;
23+ checkedArr [index ]--;
24+ }
25+
26+ for (int alphabet : checkedArr ) {
27+ if (alphabet != 0 )
28+ return false ;
29+ }
30+
31+ return true ;
32+ }
33+ }
You canβt perform that action at this time.
0 commit comments