File tree Expand file tree Collapse file tree 4 files changed +121
-0
lines changed Expand file tree Collapse file tree 4 files changed +121
-0
lines changed Original file line number Diff line number Diff line change
1
+ class Solution {
2
+ public:
3
+ void moveZeroes (vector<int >& nums) {
4
+ int next=0 ;
5
+ for (int i=0 ;i<nums.size ();i++)
6
+ {
7
+ if (nums[i])
8
+ {
9
+ nums[next]=nums[i];
10
+ next++;
11
+ }
12
+ }
13
+ for (int i=next;i<nums.size ();i++)
14
+ {
15
+ nums[i]=0 ;
16
+ }
17
+
18
+ }
19
+ };
Original file line number Diff line number Diff line change
1
+ class Solution {
2
+ public:
3
+ void sortColors (vector<int >& nums) {
4
+ int low=0 ,mid=0 ,high=nums.size ()-1 ;
5
+ while (mid<=high){
6
+
7
+ if (nums[mid]==0 )
8
+ {
9
+ swap (nums[low],nums[mid]);
10
+ low++,mid++;
11
+ }
12
+ else if (nums[mid]==1 )
13
+ {
14
+ mid++;
15
+ }
16
+ else {
17
+ swap (nums[mid],nums[high]);
18
+ high--;
19
+ }
20
+ }
21
+ }
22
+ };
Original file line number Diff line number Diff line change
1
+ class Solution {
2
+ public:
3
+ bool repeatedSubstringPattern (string s) {
4
+ string t=" " ;
5
+ if (s.size ()==1 )
6
+ {
7
+ return false ;
8
+ }
9
+ int n=s.size ();
10
+ for (int i=0 ;i<s.size ()/2 ;i++)
11
+ {
12
+ t+=s[i];
13
+ // cout<<t<<endl;
14
+ int x=t.size ();
15
+ if (n%x==0 )
16
+ {
17
+ string res;
18
+ for (int j=0 ;j<n/x;j++)
19
+ {
20
+ res+=t;
21
+ }
22
+ if (res==s)
23
+ {
24
+ // cout<<res;
25
+ return true ;
26
+
27
+ }
28
+ }
29
+
30
+ }
31
+ return false ;
32
+ }
33
+ };
Original file line number Diff line number Diff line change
1
+ class Solution {
2
+ public:
3
+ bool detectCapitalUse (string word) {
4
+ bool upper=true ,lower=true ;
5
+ if (word[0 ]-' A' >=0 &&word[0 ]-' A' <26 )
6
+ {
7
+ for (int i=1 ;i<word.size ();i++)
8
+ {
9
+ if (word[i]-' a' >=0 &&word[i]-' a' <26 )
10
+ {
11
+ continue ;
12
+ }
13
+ else {
14
+ lower=false ;
15
+ break ;
16
+ }
17
+ }
18
+ for (int i=1 ;i<word.size ();i++)
19
+ {
20
+ if (word[i]-' A' >=0 &&word[i]-' A' <26 )
21
+ {
22
+ continue ;
23
+ }
24
+ else {
25
+ upper=false ;
26
+ break ;
27
+ }
28
+ }
29
+ }
30
+ else {
31
+ upper=false ;
32
+ for (int i=1 ;i<word.size ();i++)
33
+ {
34
+ if (word[i]-' a' >=0 &&word[i]-' a' <26 )
35
+ {
36
+ continue ;
37
+ }
38
+ else {
39
+ lower=false ;
40
+ break ;
41
+ }
42
+ }
43
+ }
44
+ bool ans=upper|lower;
45
+ return ans;
46
+ }
47
+ };
You can’t perform that action at this time.
0 commit comments