Skip to content

Commit 1c6e705

Browse files
committed
2주차 문제 풀이 2개 추가
- Valid Anagram - Climbing Stairs
1 parent bbf4080 commit 1c6e705

2 files changed

Lines changed: 45 additions & 0 deletions

File tree

climbing-stairs/hwi-middle.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution {
2+
public:
3+
int climbStairs(int n) {
4+
int p = 1;
5+
int pp = 0;
6+
int cur = 0;
7+
for (int i = 0; i < n; ++i)
8+
{
9+
cur = p + pp;
10+
pp = p;
11+
p = cur;
12+
}
13+
14+
return cur;
15+
}
16+
};

valid-anagram/hwi-middle.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
class Solution {
2+
public:
3+
bool isAnagram(string s, string t) {
4+
if (s.size() != t.size())
5+
{
6+
return false;
7+
}
8+
9+
int cnt_s[26];
10+
int cnt_t[26];
11+
12+
int len = s.size();
13+
for (int i = 0; i < len; ++i)
14+
{
15+
cnt_s[s[i] - 'a']++;
16+
cnt_t[t[i] - 'a']++;
17+
}
18+
19+
for (int i = 0; i < 26; ++i)
20+
{
21+
if(cnt_s[i] != cnt_t[i])
22+
{
23+
return false;
24+
}
25+
}
26+
27+
return true;
28+
}
29+
};

0 commit comments

Comments
 (0)