Skip to content

Commit 60dc08c

Browse files
committed
try to solve
1 parent fa9b779 commit 60dc08c

1 file changed

Lines changed: 2 additions & 28 deletions

File tree

javascript/index.js

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,36 +1270,10 @@ var minRemoval = function(nums, k) {
12701270
var minimumDeletions = function(s) {
12711271

12721272
};
1273-
// let s = "aababbab";
1273+
let s = "aababbab";
12741274
/*Output: 2
12751275
Explanation: You can either:
12761276
Delete the characters at 0-indexed positions 2 and 6 ("aababbab" -> "aaabbb"), or
12771277
Delete the characters at 0-indexed positions 3 and 6 ("aababbab" -> "aabbbb").
12781278
*/
1279-
// console.log(minimumDeletions(s));
1280-
1281-
1282-
var mapWordWeights = function(words, weights) {
1283-
let sumWeights = [];
1284-
1285-
for (const element of words) {
1286-
let countLen = 0;
1287-
for(let i = 0;i < element.length;++i) {
1288-
countLen += weights[element.charCodeAt(i) - 'a'.charCodeAt()]
1289-
}
1290-
// String.fromCharCode(ascii code) => ascii code to char.
1291-
sumWeights.push(String.fromCharCode('z'.charCodeAt() - countLen % 26));
1292-
}
1293-
return sumWeights.join("")
1294-
1295-
};
1296-
let list = ["abcd","def","xyz"], weights = [5,3,12,14,1,2,3,2,10,6,6,9,7,8,7,10,8,9,6,9,9,8,3,7,7,2];
1297-
/*
1298-
Output: "rij"
1299-
Explanation:
1300-
The weight of "abcd" is 5 + 3 + 12 + 14 = 34. The result modulo 26 is 34 % 26 = 8, which maps to 'r'.
1301-
The weight of "def" is 14 + 1 + 2 = 17. The result modulo 26 is 17 % 26 = 17, which maps to 'i'.
1302-
The weight of "xyz" is 7 + 7 + 2 = 16. The result modulo 26 is 16 % 26 = 16, which maps to 'j'.
1303-
Thus, the string formed by concatenating the mapped characters is "rij".
1304-
*/
1305-
console.log(mapWordWeights(list,weights));
1279+
console.log(minimumDeletions(s));

0 commit comments

Comments
 (0)