Skip to content

Commit 7fc228e

Browse files
committed
Sync LeetCode submission Runtime - 66 ms (18.23%), Memory - 15.3 MB (100.00%)
1 parent a98cc99 commit 7fc228e

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<p>Given a string <code>s</code>, you&nbsp;can transform every letter individually to be lowercase or uppercase to create another string.</p>
2+
3+
<p>Return <em>a list of all possible strings we could create</em>. Return the output in <strong>any order</strong>.</p>
4+
5+
<p>&nbsp;</p>
6+
<p><strong class="example">Example 1:</strong></p>
7+
8+
<pre>
9+
<strong>Input:</strong> s = &quot;a1b2&quot;
10+
<strong>Output:</strong> [&quot;a1b2&quot;,&quot;a1B2&quot;,&quot;A1b2&quot;,&quot;A1B2&quot;]
11+
</pre>
12+
13+
<p><strong class="example">Example 2:</strong></p>
14+
15+
<pre>
16+
<strong>Input:</strong> s = &quot;3z4&quot;
17+
<strong>Output:</strong> [&quot;3z4&quot;,&quot;3Z4&quot;]
18+
</pre>
19+
20+
<p>&nbsp;</p>
21+
<p><strong>Constraints:</strong></p>
22+
23+
<ul>
24+
<li><code>1 &lt;= s.length &lt;= 12</code></li>
25+
<li><code>s</code> consists of lowercase English letters, uppercase English letters, and digits.</li>
26+
</ul>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Approach 1 - Backtracking
2+
3+
class Solution:
4+
def letterCasePermutation(self, s: str) -> List[str]:
5+
res = []
6+
7+
def backtrack(sub = '', i = 0):
8+
if len(sub) == len(s):
9+
res.append(sub)
10+
else:
11+
if s[i].isalpha():
12+
backtrack(sub + s[i].swapcase(), i + 1)
13+
backtrack(sub + s[i], i + 1)
14+
15+
backtrack()
16+
return res
17+

0 commit comments

Comments
 (0)