-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontest2.cpp
More file actions
56 lines (55 loc) · 1.25 KB
/
Copy pathcontest2.cpp
File metadata and controls
56 lines (55 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Biweekly Contest 109
// able to solved ploblem out of 4
//(i) 6930. Check if Array is Good
//code
//tc O(n)
class Solution {
public:
bool isGood(vector<int>& nums) {
sort(nums.begin(),nums.end());
int n = nums.size();
for(int i=0;i<n-1;i++){
if(nums[i]!=i+1){
return false;
}
}
if(nums[n-1]!=n-1){
return false;
}
return true;
}
};
//(ii) 6926. Sort Vowels in a String
//code
//tc O(nlogn)
//sc O(n)
class Solution {
public:
bool isvowel(char s){
bool flag=false;
if(s=='a' ||s== 'A' ||s== 'e' ||s== 'E' ||s== 'i' || s=='I' || s=='o' ||s== 'O' ||s== 'u' || s=='U'){
flag=true;
}
return flag;
}
string sortVowels(string s) {
vector<char> temp;
string ans;
for(int i=0;i<s.size();i++){
if(isvowel(s[i])){
temp.push_back(s[i]);
}
}
sort(temp.begin(),temp.end());
int count=0;
for(int i=0;i<s.size();i++){
if(isvowel(s[i])){
ans.push_back(temp[count]);
count++;
}else{
ans.push_back(s[i]);
}
}
return ans;
}
};