File tree Expand file tree Collapse file tree 2 files changed +59
-0
lines changed Expand file tree Collapse file tree 2 files changed +59
-0
lines changed Original file line number Diff line number Diff line change 1+ /**
2+ * Runtime: 0ms
3+ * Time Complexity: O(n)
4+ *
5+ * Memory: 42.18MB
6+ * Space Complexity: O(n)
7+ *
8+ * Approach: DPλ₯Ό μ΄μ©ν μ νμ νμ©
9+ * - nλ²μ§Έ κ³λ¨μ λλ¬νλ λ°©λ²μ (n-1)λ²μ§Έ κ³λ¨μμ ν μΉΈ μ¬λΌμ€λ λ°©λ²κ³Ό
10+ * (n-2)λ²μ§Έ κ³λ¨μμ λ μΉΈ μ¬λΌμ€λ λ°©λ²μ ν©κ³Ό κ°μ
11+ */
12+ class Solution {
13+ public int climbStairs (int n ) {
14+ if (n == 1 ) return 1 ;
15+ else if (n == 2 ) return 2 ;
16+
17+ int [] dp = new int [n +1 ];
18+ dp [1 ] = 1 ;
19+ dp [2 ] = 2 ;
20+ for (int i =3 ; i <dp .length ; i ++) {
21+ dp [i ] = dp [i -1 ] + dp [i -2 ];
22+ }
23+
24+ return dp [n ];
25+ }
26+ }
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