58 Star 717 Fork 331

doocs/leetcode

Create your Gitee Account
Explore and code with more than 13.5 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
Solution.ts 1.03 KB
Copy Edit Raw Blame History
ylb authored 2025-04-03 08:32 +08:00 . feat: add solutions to lc problem: No.0604 (#4326)
class StringIterator {
private d: [string, number][] = [];
private p: number = 0;
constructor(compressedString: string) {
const n = compressedString.length;
let i = 0;
while (i < n) {
const c = compressedString[i];
let x = 0;
i++;
while (i < n && !isNaN(Number(compressedString[i]))) {
x = x * 10 + Number(compressedString[i]);
i++;
}
this.d.push([c, x]);
}
}
next(): string {
if (!this.hasNext()) {
return ' ';
}
const ans = this.d[this.p][0];
this.d[this.p][1]--;
if (this.d[this.p][1] === 0) {
this.p++;
}
return ans;
}
hasNext(): boolean {
return this.p < this.d.length && this.d[this.p][1] > 0;
}
}
/**
* Your StringIterator object will be instantiated and called as such:
* var obj = new StringIterator(compressedString)
* var param_1 = obj.next()
* var param_2 = obj.hasNext()
*/
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/Doocs/leetcode.git
[email protected]:Doocs/leetcode.git
Doocs
leetcode
leetcode
main

Search