@@ -1171,25 +1171,44 @@ var specialTriplets = function(nums) {
11711171 */
11721172var reverseVowels = function ( s ) {
11731173 let vowels = [ "a" , "e" , "i" , "o" , "u" , "A" , "E" , "I" , "O" , "U" ] ;
1174- let splitS = s . split ( "" ) ;
1175- // 2 pointer?
1176- let j = splitS . length - 1 , i = 0 ;
1177- while ( i < j ) {
1178- if ( ! vowels . includes ( splitS [ i ] , i ) ) {
1179- i ++ ;
1180- continue ;
1174+ // let splitS = s.split("");
1175+ // let res = [];
1176+ // // 2 pointer?
1177+ // let j = s.length - 1,i = 0;
1178+ // while(i < j){
1179+ // if(i < j && !vowels.includes(s,i)){
1180+ // i++;
1181+ // }
1182+ // if(i < j && !vowels.includes(s,j)){
1183+ // j--;
1184+ // }
1185+ // let char = res[i];
1186+ // res[i] = res[j];
1187+ // res[j] = char;
1188+ // i++;
1189+ // j--;
1190+ // }
1191+ // return res.join("");
1192+
1193+ let j = s . length - 1 ;
1194+ // let vowelsRev = new Map();
1195+ let hasVowels = [ ] ;
1196+
1197+ for ( let i = 0 ; i < s . length ; ++ i ) {
1198+ if ( i < j && vowels . includes ( s [ i ] ) ) {
1199+ // vowelsRev.push(s[i].split("").join(""));
1200+ hasVowels . push ( s [ i ] ) ;
11811201 }
1182- if ( ! vowels . includes ( splitS [ j ] , j ) ) {
1183- j -- ;
1184- continue ;
1202+ // vowelsRev.set(i,reverse);
1203+ }
1204+ let reverse = hasVowels . reverse ( ) . join ( "" ) ;
1205+ // console.log(reverse)
1206+ let res = "" ;
1207+ for ( let i = 0 ; i < s . length ; ++ i ) {
1208+ if ( i < j && vowels . includes ( reverse [ i ] ) ) {
1209+
11851210 }
1186- let char = splitS [ i ] ;
1187- splitS [ i ] = splitS [ j ] ;
1188- splitS [ j ] = char ;
1189- i ++ ;
1190- j -- ;
11911211 }
1192- return splitS . join ( "" ) ;
11931212} ;
11941213let s = "IceCreAm" ;
11951214/**
@@ -1198,7 +1217,7 @@ let s = "IceCreAm";
11981217 * The vowels in s are ['I', 'e', 'e', 'A']. On reversing the vowels, s becomes "AceCreIm".
11991218 *
12001219 */
1201- // console.log(reverseVowels(s));
1220+ console . log ( reverseVowels ( s ) ) ;
12021221
12031222/**
12041223 * Alphabet symmetry
@@ -1293,4 +1312,26 @@ let nums = [1,6,2,9], k = 3;
12931312// 2
12941313// Remove nums[0] = 1 and nums[3] = 9 to get nums = [6, 2].
12951314// Now max = 6, min = 2 and max <= min * k as 6 <= 2 * 3. Thus, the answer is 2.
1296- console . log ( minRemoval ( nums , k ) ) ;
1315+ // console.log(minRemoval(nums,k));
1316+
1317+
1318+ /**
1319+ * 1653. Minimum Deletions to Make String Balanced
1320+ *
1321+ * 參數s中只有'a' & 'b'這兩個字母。
1322+ * 刪除任一字母使s balanced,若不存在一對index (i,j) 使得 i < j 且 s[i] = 'b' 且 s[j] = 'a',則s 是balanced。
1323+ * 回傳最小須刪除幾次才能使s balanced
1324+ *
1325+ * @param {string } s
1326+ * @return {number }
1327+ */
1328+ var minimumDeletions = function ( s ) {
1329+
1330+ } ;
1331+ // let s = "aababbab";
1332+ /*Output: 2
1333+ Explanation: You can either:
1334+ Delete the characters at 0-indexed positions 2 and 6 ("aababbab" -> "aaabbb"), or
1335+ Delete the characters at 0-indexed positions 3 and 6 ("aababbab" -> "aabbbb").
1336+ */
1337+ // console.log(minimumDeletions(s));
0 commit comments