Skip to content

Latest commit

 

History

History
58 lines (41 loc) · 1.52 KB

_784. Letter Case Permutation.md

File metadata and controls

58 lines (41 loc) · 1.52 KB

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

Back to top


First completed : June 15, 2024

Last updated : June 15, 2024


Related Topics : String, Backtracking, Bit Manipulation

Acceptance Rate : 74.52 %


Solutions

Python

class Solution:
    def letterCasePermutation(self, s: str) -> List[str]:
        s = list(s)
        
        lowercase = 'abcdefghijklmnopqrstuvwxyz'
        uppwercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
        matches = {lowercase[x]: uppwercase[x] for x in range(len(lowercase))}
        matches.update((uppwercase[x], lowercase[x]) for x in range(len(lowercase)))

        output = []
        currentOutput = []
        
        def helper() -> None :
            if len(currentOutput) == len(s) :
                output.append(''.join(currentOutput))
                return
            
            currentOutput.append(s[len(currentOutput)])
            helper()
            currentOutput.pop()

            if s[len(currentOutput)].isnumeric() :
                return

            currentOutput.append(matches[s[len(currentOutput)]])
            helper()
            currentOutput.pop()

        helper()
        return output