class Solution {
public :
string mergeAlternately ( string word1, string word2) {
string res;
int i = 0 ;
int j = 0 ;
int m = word1. size ( ) ;
int n = word2. size ( ) ;
res. reserve ( m + n) ;
while ( i < m || j < n) {
if ( i < m) {
res. push_back ( word1[ i] ) ;
i ++ ;
}
if ( j < n) {
res. push_back ( word2[ j] ) ;
j ++ ;
}
}
return res;
}
} ;
class Solution {
public :
int gcd ( int a, int b) {
return b == 0 ? a : gcd ( b, a % b) ;
}
string gcdOfStrings ( string str1, string str2) {
if ( str1 + str2 != str2 + str1) return "" ;
return str1. substr ( 0 , gcd ( str1. size ( ) , str2. size ( ) ) ) ;
}
} ;
class Solution {
public :
vector< bool > kidsWithCandies ( vector< int > & candies, int extraCandies) {
int minx = INT_MIN;
for ( auto can : candies) {
if ( can > minx) {
minx = can;
}
}
vector< bool > res ( candies. size ( ) ) ;
for ( int i = 0 ; i < candies. size ( ) ; i++ ) {
res[ i] = ( candies[ i] + extraCandies) >= minx;
}
return res;
}
} ;
class Solution {
public :
bool canPlaceFlowers ( vector< int > & flowerbed, int n) {
int length = flowerbed. size ( ) ;
for ( int i = 0 ; i < length; i++ ) {
if ( flowerbed[ i] == 0 && ( ( i == 0 || flowerbed[ i - 1 ] == 0 ) ) && ( ( i == length - 1 ) || flowerbed[ i + 1 ] == 0 ) ) {
n -- ;
flowerbed[ i] = 1 ;
}
}
return false ;
}
} ;
class Solution {
public :
string reverseVowels ( string s) {
int l = 0 ;
int r = s. size ( ) - 1 ;
unordered_set < char > vowels = { 'a' , 'e' , 'i' , 'o' , 'u' , 'A' , 'E' , 'I' , 'O' , 'U' } ;
while ( l < r ) {
if ( ! vowels. count ( s[ l] ) l ++ ;
else if ( ! vowels. count ( s[ r] ) )
r -- ;
else swap ( s[ l++ ] , s[ r-- ] ) ;
}
}
return s;
}
} ;