File tree Expand file tree Collapse file tree 2 files changed +52
-0
lines changed Expand file tree Collapse file tree 2 files changed +52
-0
lines changed Original file line number Diff line number Diff line change 1+ class Solution {
2+ public:
3+ int climbStairs (int n) {
4+ std::map<int , int > stepMap;
5+ stepMap[1 ] = 1 ;
6+ stepMap[2 ] = 2 ;
7+
8+ if (n == 1 ) {
9+ return stepMap[n];
10+ }
11+
12+ for (int i = 3 ; i <= n; i++) {
13+ stepMap[i] = stepMap[i - 1 ] + stepMap[i - 2 ];
14+ }
15+
16+ return stepMap[n];
17+ }
18+ };
Original file line number Diff line number Diff line change 1+ ' ' '
2+ Time Complexity: O(n log n)
3+ - 분류 정렬에서 O(n log n) 발생
4+
5+ Run time
6+ - 7ms
7+
8+ Memory
9+ - 9.56 MB
10+
11+ 최적화쪽으로 수정 추가 필요
12+ ' ' '
13+ class Solution {
14+ public:
15+ bool isAnagram (string s, string t) {
16+ // 선 길이 체크
17+ if (s.length () != t.length ()) {
18+ return false ;
19+ }
20+
21+ // 두 배열 정렬(n log n)
22+ std::sort (s.begin (), s.end ());
23+ std::sort (t.begin (), t.end ());
24+
25+ // 비교하여 다르면 false
26+ for (int i = 0 ; i < s.length (); i++) {
27+ if (s[i] != t[i]) {
28+ return false ;
29+ }
30+ }
31+
32+ return true ;
33+ }
34+ };
You can’t perform that action at this time.
0 commit comments