File tree Expand file tree Collapse file tree 2 files changed +57
-0
lines changed Expand file tree Collapse file tree 2 files changed +57
-0
lines changed Original file line number Diff line number Diff line change
1
+ /*
2
+ * ํ์ด: n๋ฒ์งธ ๊ณ๋จ์ ๋๋ฌํ๋ ๊ฒฝ์ฐ๋ ๋ค์ ๋ ๊ฐ์ง๋ก ๋๋๋ค.
3
+ * 1. (n-1)๋ฒ์งธ ๊ณ๋จ์์ ํ ๊ณ๋จ ์ค๋ฅด๋ ๊ฒฝ์ฐ
4
+ * 2. (n-2)๋ฒ์งธ ๊ณ๋จ์์ ๋ ๊ณ๋จ ์ค๋ฅด๋ ๊ฒฝ์ฐ
5
+ * ๋ฐ๋ผ์, n๊ฐ์ ๊ณ๋จ์ ์ฌ๋ผ๊ฐ๋ ๋ฐฉ๋ฒ์ ๊ฒฝ์ฐ์ ์ F(n)์
6
+ * F(n-1)๊ณผ F(n-2)์ ํฉ๊ณผ ๊ฐ๋ค.
7
+ * ์๊ฐ ๋ณต์ก๋: O(n)
8
+ * ๊ณต๊ฐ ๋ณต์ก๋: O(1)
9
+ */
10
+ class Solution {
11
+ public int climbStairs (int n ) {
12
+ if (n == 1 ) return 1 ;
13
+
14
+ int step1 = 1 ;
15
+ int step2 = 2 ;
16
+
17
+ for (int i = 3 ; i <= n ; i ++) {
18
+ int temp = step1 + step2 ;
19
+ step1 = step2 ;
20
+ step2 = temp ;
21
+ }
22
+
23
+ return step2 ;
24
+ }
25
+ }
26
+
Original file line number Diff line number Diff line change
1
+ import java .util .Arrays ;
2
+ /*
3
+ ํ์ด:
4
+ - ๋ฌธ์์ด s์ t๋ฅผ ๋ฐฐ์ด๋ก ์ ์ฅํ๊ณ , ์ค๋ฆ์ฐจ์์ผ๋ก ๋ฌธ์๋ฅผ ์ ๋ ฌํ๋ค.
5
+ - ์ ๋ ฌ๋ ๋ ๋ฐฐ์ด์ด ๋์ผํ๋ฉด ์ ๋๊ทธ๋จ์ผ๋ก ํ๋จํ๋ค.
6
+ ์๊ฐ ๋ณต์ก๋:
7
+ - O(n log n)
8
+ - ๋ฐฐ์ด ์ ๋ ฌ์ O(n log n)์ ์๊ฐ ๋ณต์ก๋๋ฅผ ๊ฐ๋๋ค.
9
+ ๊ณต๊ฐ ๋ณต์ก๋:
10
+ - O(n)
11
+ - ๋ฌธ์์ด์ ๋ฐฐ์ด๋ก ๋ณํํ๊ณ ์ ๋ ฌํ ๋ O(n)์ ๊ณต๊ฐ ๋ณต์ก๋๋ฅผ ๊ฐ๋๋ค.
12
+ */
13
+ class Solution {
14
+ public boolean isAnagram (String s , String t ) {
15
+ // ๋ ๋ฌธ์์ด์ ๊ธธ์ด๊ฐ ๋ค๋ฅด๋ฉด false
16
+ if (s .length () != t .length ()) {
17
+ return false ;
18
+ }
19
+ //๋ฌธ์์ด์ ๋ฌธ์๋ฅผ ๋ฐฐ์ด๋ก ์ ์ฅํ๋ค
20
+ char [] sArray = s .toCharArray ();
21
+ char [] tArray = t .toCharArray ();
22
+
23
+ // ๊ฐ ๋ฐฐ์ด์ ๋ฌธ์๋ฅผ ์ค๋ฆ์ฐจ์์ผ๋ก ์ ๋ ฌํ๋ค
24
+ Arrays .sort (sArray );
25
+ Arrays .sort (tArray );
26
+
27
+ // ์ ๋ ฌํ ๋ ๋ฐฐ์ด์ ๋น๊ตํ๋ค.
28
+ return Arrays .equals (sArray , tArray );
29
+ }
30
+ }
31
+
You canโt perform that action at this time.
0 commit comments