Skip to content

Commit 2bf8fc0

Browse files
committed
initial commit
1 parent 46b2884 commit 2bf8fc0

File tree

5 files changed

+70
-0
lines changed

5 files changed

+70
-0
lines changed

โ€Ž3sum/haung921209.mdโ€Ž

Whitespace-only changes.

โ€Žclimbing-stairs/haung921209.mdโ€Ž

Whitespace-only changes.

โ€Žproduct-of-array-except-self/haung921209.mdโ€Ž

Whitespace-only changes.
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
2+
```cpp
3+
class Solution {
4+
public:
5+
bool isAnagram(string s, string t) {
6+
if (s.length() != t.length())
7+
return false;
8+
sort(s.begin(), s.end());
9+
sort(t.begin(), t.end());
10+
return s==t;
11+
}
12+
};
13+
```
14+
15+
- O(nlogn)
16+
- std์˜ sort๋ฅผ ์‚ฌ์šฉ
17+
18+
```
19+
class Solution {
20+
public:
21+
bool isAnagram(string s, string t) {
22+
if (s.length() != t.length())
23+
return false;
24+
unordered_map<char, int> dict;
25+
for(auto c:s){
26+
dict[c]++;
27+
}
28+
for(auto c:t){
29+
if(dict[c]==0){
30+
return false;
31+
}
32+
dict[c]--;
33+
}
34+
return true;
35+
36+
}
37+
};
38+
```
39+
40+
- O(n)? => O(nlogn)
41+
- map insert์—์„œ O(logn)์”ฉ ์†Œ์š”๋จ
42+
- ์œ„์˜ sort๋ณด๋‹ค๋Š” ํšจ์œจ์ ์ผ ์ˆ˜ ์žˆ์Œ
43+
44+
```cpp
45+
class Solution {
46+
public:
47+
bool isAnagram(string s, string t) {
48+
if (s.length() != t.length())
49+
return false;
50+
vector<int>cntVec(26, 0);
51+
for(auto c:s){
52+
cntVec[(int(c-'a'))]++;
53+
}
54+
for(auto c:t){
55+
cntVec[(int(c-'a'))]--;
56+
}
57+
for(auto cnt:cntVec){
58+
if(cnt!=0){
59+
return false;
60+
}
61+
}
62+
return true;
63+
64+
}
65+
};
66+
```
67+
- O(n)
68+
- ๋‘๋ฒˆ์งธ ๊ฒƒ๊ณผ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ ์ €์žฅ๊ณต๊ฐ„์ด ํ•„์š”ํ•˜๋‚˜, O(n)์œผ๋กœ ์ข…๋ฃŒ ๊ฐ€๋Šฅ
69+
- ์‹œ๊ฐ„ ๋ณต์žก๋„๋ฅผ ์ตœ๋Œ€ํ•œ ์ตœ์ ํ™” ํ•˜๋Š” ๊ฒฝ์šฐ
70+

โ€Žvalidate-binary-search-tree/haung921209.mdโ€Ž

Whitespace-only changes.

0 commit comments

Comments
ย (0)