Skip to content

Commit 6a55563

Browse files
committed
chore: alg
1 parent 91e09f7 commit 6a55563

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
const rl = require("readline").createInterface({ input: process.stdin });
2+
var iter = rl[Symbol.asyncIterator]();
3+
const readline = async () => (await iter.next()).value;
4+
5+
void async function () {
6+
const a = (await readline()).split('').map(it => Number(it))
7+
const idxs = a.reduce((s, it, idx) => { // reduce 支持第三个参数 idx
8+
if (it)
9+
s.push(a.length - idx)
10+
return s
11+
}, [])
12+
13+
// 注意特殊情况!!
14+
if (idxs.length === 1) {
15+
console.log('0')
16+
return
17+
}
18+
if (idxs.length === 0) {
19+
console.log('1')
20+
}
21+
22+
// console.log(idxs)
23+
let ans = ''
24+
while (idxs.length > 1) {
25+
let cur = idxs.pop()
26+
// while(ans.length < cur-1){
27+
ans = '0'.repeat((cur - 1) - ans.length) + ans
28+
// }
29+
ans = '1' + ans
30+
while (idxs[idxs.length - 1] === cur + 1) {
31+
idxs.pop()
32+
cur++ // 连锁倾销
33+
}
34+
idxs.push(cur + 1)
35+
}
36+
console.log(ans)
37+
}()

0 commit comments

Comments
 (0)