Skip to content

Commit 123611e

Browse files
authored
Merge pull request #2055 from YuuuuuuYu/main
[YuuuuuuYu] WEEK 02 Solutions
2 parents cd317ff + 9300c7e commit 123611e

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
}

β€Žvalid-anagram/YuuuuuuYu.javaβ€Ž

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
}

0 commit comments

Comments
Β (0)