File tree Expand file tree Collapse file tree 1 file changed +10
-13
lines changed Expand file tree Collapse file tree 1 file changed +10
-13
lines changed Original file line number Diff line number Diff line change 11/**
2- * ์๊ฐ ๋ณต์ก๋: O(NlogN)
3- * - Arrays.sort() > Dual-Pivot QuickSort
4- *
5- * ๊ณต๊ฐ ๋ณต์ก๋: O(N)
6- *
72 * ์ฒ์ ๋ฌธ์ ๋ฅผ ๋ณด๊ณ ๋ค์๋ ์๊ฐ: ์ ๋ ฌ ์์ผ์ ๊ฐ์ผ๋ฉด anagram?
8- * -> ์, ๊ทธ๋ฌ๋ฉด ๋ฑ์ฅํ ๋ฌธ์์ ๋น๋์๊ฐ ๊ฐ๋ค?
9- * -> ๊ฒฐ๊ตญ 26 ์ฌ์ด์ฆ๊ฐ ์ธํ์ ์ํฅ์ ๋ฐ์ง ์์ผ๋ฏ๋ก ๊ณต๊ฐ ๋ณต์ก๋๋ฅผ O(1)๋ก ๊ฐ์ ํ ์ ์๊ณ ,
10- * -> ์๊ฐ ๋ณต์ก๋๋ O(N)์ผ๋ก ๊ฐ์ ํ ์ ์๊ฒ ๋ค.
3+ * ๊ทผ๋ฐ, ์ ๋ ฌ ์์ผ์ ๊ฐ๋ค๋ฉด, ๊ฒฐ๊ตญ ๋ฌธ์์ด์ ๊ตฌ์ฑํ๋ ๊ฐ ๋ฌธ์์ ๋น๋์๊ฐ ๊ฐ๋ค.
4+ *
5+ * ์๊ฐ ๋ณต์ก๋: O(N)
6+ * ๊ณต๊ฐ ๋ณต์ก๋: O(1)
117 */
128class Solution {
139 public boolean isAnagram (String s , String t ) {
1410 if (s .length () != t .length ()) return false ;
1511
1612 int [] charCount = new int [26 ];
1713
18- for (char c : s . toCharArray () ) {
19- charCount [c - 'a' ]++;
14+ for (int i = 0 ; i < s . length (); i ++ ) {
15+ charCount [s . charAt ( i ) - 'a' ]++;
2016 }
2117
22- for (char c : t .toCharArray ()) {
23- charCount [c - 'a' ]--;
24- if (charCount [c - 'a' ] < 0 ) {
18+ for (int i = 0 ; i < t .length (); i ++) {
19+ int index = t .charAt (i ) - 'a' ;
20+ charCount [index ]--;
21+ if (charCount [index ] < 0 ) {
2522 return false ;
2623 }
2724 }
You canโt perform that action at this time.
0 commit comments