Skip to content

Commit 916bb11

Browse files
committedJul 6, 2023
❌ [443] a1
1 parent 7e1984c commit 916bb11

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed
 

‎443/my_solution.js

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
* @param {character[]} chars
3+
* @return {number}
4+
*/
5+
var compress = function (chars) {
6+
let charAppearMap = new Map(), s = []
7+
8+
for (let i = 0; i < chars.length; i++) {
9+
charAppearMap.set(chars[i], (charAppearMap.get(chars[i]) ?? 0) + 1);
10+
}
11+
12+
for (let [key, value] of charAppearMap) {
13+
if (value === 1) {
14+
s.push(key);
15+
} else {
16+
s.push(key);
17+
let keys = value.toString().split("");
18+
while (keys.length > 0) {
19+
let key = keys.shift();
20+
s.push(key);
21+
}
22+
}
23+
}
24+
25+
console.log("s")
26+
console.log(s)
27+
for (let i = 0; i < s.length; i++) {
28+
chars[i] = s[i];
29+
}
30+
31+
console.log("char")
32+
console.log(chars)
33+
console.log(chars.length)
34+
return s.length;
35+
};
36+
37+
38+
let x =
39+
// compress(["a", "a", "b", "b", "c", "c", "c"])
40+
compress(["a", "b", "b", "b", "b", "b", "b", "b", "b", "b", "b", "b", "b"])
41+
42+
console.log("Result")
43+
console.log(x)

‎443/solution.js

Whitespace-only changes.

‎README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
- [417. Pacific Atlantic Water Flow](./417/)
8484
- [424. Longest Repeating Character Replacement](./424/)
8585
- [435. Non-overlapping Intervals](./435/)
86+
- [443. String Compression](./443/)
8687
- [530. Minimum Absolute Difference in BST](./530/)
8788
- [572. Subtree of Another Tree](./572/)
8889
- [605. Can Place Flowers](./605/)
@@ -158,7 +159,7 @@ Batch create:
158159
NOTE: JS IS HERE
159160
-->
160161
```ssh
161-
chapter=334 && mkdir ./$chapter && touch ./$chapter/my_solution.js && touch ./$chapter/solution.js && alias x="node ./$chapter/my_solution.js"
162+
chapter=443 && mkdir ./$chapter && touch ./$chapter/my_solution.js && touch ./$chapter/solution.js && alias x="node ./$chapter/my_solution.js"
162163
```
163164
> then you can use `x` for quick debug.
164165

0 commit comments

Comments
 (0)
Please sign in to comment.