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 1
1
/**
2
- * ์๊ฐ ๋ณต์ก๋: O(NlogN)
3
- * - Arrays.sort() > Dual-Pivot QuickSort
4
- *
5
- * ๊ณต๊ฐ ๋ณต์ก๋: O(N)
6
- *
7
2
* ์ฒ์ ๋ฌธ์ ๋ฅผ ๋ณด๊ณ ๋ค์๋ ์๊ฐ: ์ ๋ ฌ ์์ผ์ ๊ฐ์ผ๋ฉด anagram?
8
- * -> ์, ๊ทธ๋ฌ๋ฉด ๋ฑ์ฅํ ๋ฌธ์์ ๋น๋์๊ฐ ๊ฐ๋ค?
9
- * -> ๊ฒฐ๊ตญ 26 ์ฌ์ด์ฆ๊ฐ ์ธํ์ ์ํฅ์ ๋ฐ์ง ์์ผ๋ฏ๋ก ๊ณต๊ฐ ๋ณต์ก๋๋ฅผ O(1)๋ก ๊ฐ์ ํ ์ ์๊ณ ,
10
- * -> ์๊ฐ ๋ณต์ก๋๋ O(N)์ผ๋ก ๊ฐ์ ํ ์ ์๊ฒ ๋ค.
3
+ * ๊ทผ๋ฐ, ์ ๋ ฌ ์์ผ์ ๊ฐ๋ค๋ฉด, ๊ฒฐ๊ตญ ๋ฌธ์์ด์ ๊ตฌ์ฑํ๋ ๊ฐ ๋ฌธ์์ ๋น๋์๊ฐ ๊ฐ๋ค.
4
+ *
5
+ * ์๊ฐ ๋ณต์ก๋: O(N)
6
+ * ๊ณต๊ฐ ๋ณต์ก๋: O(1)
11
7
*/
12
8
class Solution {
13
9
public boolean isAnagram (String s , String t ) {
14
10
if (s .length () != t .length ()) return false ;
15
11
16
12
int [] charCount = new int [26 ];
17
13
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' ]++;
20
16
}
21
17
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 ) {
25
22
return false ;
26
23
}
27
24
}
You canโt perform that action at this time.
0 commit comments