Skip to content

Latest commit

 

History

History
56 lines (44 loc) · 1.61 KB

_942. DI String Match.md

File metadata and controls

56 lines (44 loc) · 1.61 KB

All prompts are owned by LeetCode. To view the prompt, click the title link above.

Back to top


First completed : February 18, 2025

Last updated : February 18, 2025


Related Topics : Array, Two Pointers, String, Greedy

Acceptance Rate : 79.86 %


Solutions

Python

class Solution:
    def diStringMatch(self, s: str) -> List[int]:
        minn, maxx = 0, 0
        output = [0]
        for c in s :
            if c == 'I' :
                output.append(maxx := maxx + 1)
            else :
                output.append(minn := minn - 1)
        return [x - minn for x in output]
class Solution:
    def diStringMatch(self, s: str) -> List[int]:
        minn, maxx = 0, 0
        output = [0] + [(maxx := maxx + 1) if c == 'I' else (minn := minn - 1) for c in s]
        return [x - minn for x in output]
class Solution:
    def diStringMatch(self, s: str) -> List[int]:
        return [(l := 0 if 'l' not in locals() else l + 1) if c == 'I' else (r := len(s) if 'r' not in locals() else r - 1) for c in s] + [l + 1 if 'l' in locals() else r - 1]