Skip to content

Commit 0855905

Browse files
committed
Left Over
1 parent cffc694 commit 0855905

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

242. Valid Anagram.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution(object):
2+
def isAnagram(self, s, t):
3+
#First Method
4+
if(len(s)!=len(t)):
5+
return False
6+
7+
c_s = {}
8+
c_t = {}
9+
10+
for i in range(len(s)):
11+
c_s[s[i]] = c_s.get(s[i],0) + 1
12+
c_t[t[i]] = c_t.get(t[i],0) + 1
13+
return c_s == c_t
14+
15+
#Second Method
16+
return ''.join(sorted(s)) == ''.join(sorted(t))
17+

trial

124 KB
Binary file not shown.

trial.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#include <sstream>
2+
#include <vector>
3+
#include <iostream>
4+
using namespace std;
5+
6+
vector<int> parseInts(string str) {
7+
stringstream ss(str);
8+
char word;
9+
string empty = "";
10+
vector<int> n;
11+
while(ss>>word)
12+
{
13+
empty += word;
14+
if(ss.peek()==',')
15+
{
16+
n.push_back(stoi(empty));
17+
empty = "";
18+
ss.ignore();
19+
}
20+
21+
}
22+
n.push_back(stoi(empty));
23+
return n;
24+
}
25+
26+
int main() {
27+
string str = "23,45,56";
28+
vector<int> integers = parseInts(str);
29+
for(int i = 0; i < integers.size(); i++) {
30+
cout << integers[i] << "\n";
31+
}
32+
33+
return 0;
34+
}

0 commit comments

Comments
 (0)