File tree Expand file tree Collapse file tree 3 files changed +51
-0
lines changed Expand file tree Collapse file tree 3 files changed +51
-0
lines changed Original file line number Diff line number Diff line change
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
+
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments