Find the Sequence of Strings Appeared on the Screen
MediumStringSimulation
Solution
export function stringSequence(target: string): string[] {
const answer = [];
let s = '';
for (const char of target) {
for (const alphabet of toAlphabet(char)) {
answer.push(s + alphabet);
}
s += char;
}
return answer;
}
function* toAlphabet(char: string) {
const alphabets = 'abcdefghijklmnopqrstuvwxyz';
for (const alphabet of alphabets) {
if (char < alphabet) return;
yield alphabet;
}
}
Complexity
- Time:
- Space: , 정답에 대한 복잡도