File tree 3 files changed +102
-0
lines changed
3 files changed +102
-0
lines changed Original file line number Diff line number Diff line change
1
+ class Solution {
2
+ public:
3
+ bool isPalindrome (string s)
4
+ {
5
+ string toreturn = " " ;
6
+
7
+ for (auto x: s)
8
+ {
9
+ if (iswalnum (x))
10
+ {
11
+ toreturn+=tolower (x);
12
+ }
13
+ }
14
+ string x = toreturn;
15
+ reverse (toreturn.begin (),toreturn.end ());
16
+ return x==toreturn;
17
+ }
18
+ };
Original file line number Diff line number Diff line change
1
+ class Solution {
2
+ public:
3
+ int singleNumber (vector<int >& nums)
4
+ {
5
+ vector<int > result;
6
+ for (int i = 0 ;i<32 ;i++)
7
+ {
8
+ int one = 0 ;
9
+ int zero = 0 ;
10
+ for (auto x: nums)
11
+ {
12
+ if ((x>>i)&1 )
13
+ {
14
+ one+=1 ;
15
+ }
16
+ else
17
+ {
18
+ zero+=1 ;
19
+ }
20
+ }
21
+
22
+ one %= 3 ;
23
+ zero %= 3 ;
24
+
25
+ if (one==0 )
26
+ {
27
+ result.push_back (0 );
28
+ }
29
+ if (zero==0 )
30
+ {
31
+ result.push_back (1 );
32
+ }
33
+ }
34
+ long ans = 0 ;
35
+ for (int i = 0 ;i<32 ;i++)
36
+ {
37
+ ans += result[i]*long (pow (2 ,i));
38
+ }
39
+
40
+ return ans;
41
+ }
42
+ };
Original file line number Diff line number Diff line change
1
+ class Solution {
2
+ public:
3
+ vector<int > plusOne (vector<int >& digits)
4
+ {
5
+ reverse (digits.begin (),digits.end ());
6
+ int carry = 0 ;
7
+ bool flag = false ;
8
+ digits[0 ] += 1 ;
9
+ if (digits[0 ]>=10 )
10
+ {
11
+ digits[0 ] %= 10 ;
12
+ carry = 1 ;
13
+ flag = true ;
14
+ }
15
+ else
16
+ {
17
+ carry = 0 ;
18
+ }
19
+ for (int i = 1 ;i<digits.size ();i++)
20
+ {
21
+ flag = false ;
22
+ digits[i] += carry;
23
+
24
+ if (digits[i]>=10 )
25
+ {
26
+ digits[i] %= 10 ;
27
+ carry = 1 ;
28
+ flag = true ;
29
+ }
30
+ else
31
+ {
32
+ carry = 0 ;
33
+ }
34
+ }
35
+ if (flag)
36
+ {
37
+ digits.push_back (1 );
38
+ }
39
+ reverse (digits.begin (),digits.end ());
40
+ return digits;
41
+ }
42
+ };
You can’t perform that action at this time.
0 commit comments