784:字母大小写全排列(未完成)
This commit is contained in:
parent
c26668abd4
commit
2e3ca5156b
72
src/main/java/leetcode/editor/cn/LetterCasePermutation.java
Normal file
72
src/main/java/leetcode/editor/cn/LetterCasePermutation.java
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
//给定一个字符串S,通过将字符串S中的每个字母转变大小写,我们可以获得一个新的字符串。返回所有可能得到的字符串集合。
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// 示例:
|
||||||
|
//输入:S = "a1b2"
|
||||||
|
//输出:["a1b2", "a1B2", "A1b2", "A1B2"]
|
||||||
|
//
|
||||||
|
//输入:S = "3z4"
|
||||||
|
//输出:["3z4", "3Z4"]
|
||||||
|
//
|
||||||
|
//输入:S = "12345"
|
||||||
|
//输出:["12345"]
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// 提示:
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// S 的长度不超过12。
|
||||||
|
// S 仅由数字和字母组成。
|
||||||
|
//
|
||||||
|
// Related Topics 位运算 字符串 回溯
|
||||||
|
// 👍 282 👎 0
|
||||||
|
|
||||||
|
package leetcode.editor.cn;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
//784:字母大小写全排列
|
||||||
|
class LetterCasePermutation{
|
||||||
|
public static void main(String[] args) {
|
||||||
|
//测试代码
|
||||||
|
Solution solution = new LetterCasePermutation().new Solution();
|
||||||
|
solution.letterCasePermutation("a1b2");
|
||||||
|
}
|
||||||
|
//力扣代码
|
||||||
|
//leetcode submit region begin(Prohibit modification and deletion)
|
||||||
|
class Solution {
|
||||||
|
public List<String> letterCasePermutation(String s) {
|
||||||
|
char[] chs = s.toCharArray();
|
||||||
|
List<char[]> list = new ArrayList<>();
|
||||||
|
list.add(chs);
|
||||||
|
for (int i = 0; i < chs.length; i++) {
|
||||||
|
if(Character.isDigit(chs[i])){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
List<char[]> temp = new ArrayList<>();
|
||||||
|
for (char[] chList:list) {
|
||||||
|
temp.add(chList);
|
||||||
|
if(chList[i]<'a'){
|
||||||
|
chList[i] += 32;
|
||||||
|
temp.add(chList);
|
||||||
|
}else {
|
||||||
|
chList[i] -= 32;
|
||||||
|
temp.add(chList);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
list = temp;
|
||||||
|
}
|
||||||
|
List<String> result = new ArrayList<>();
|
||||||
|
for (int i = 0; i < list.size(); i++) {
|
||||||
|
result.add(new String(list.get(i)));
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//leetcode submit region end(Prohibit modification and deletion)
|
||||||
|
|
||||||
|
}
|
24
src/main/java/leetcode/editor/cn/LetterCasePermutation.md
Normal file
24
src/main/java/leetcode/editor/cn/LetterCasePermutation.md
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
<p>给定一个字符串<code>S</code>,通过将字符串<code>S</code>中的每个字母转变大小写,我们可以获得一个新的字符串。返回所有可能得到的字符串集合。</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<pre><strong>示例:</strong>
|
||||||
|
<strong>输入:</strong>S = "a1b2"
|
||||||
|
<strong>输出:</strong>["a1b2", "a1B2", "A1b2", "A1B2"]
|
||||||
|
|
||||||
|
<strong>输入:</strong>S = "3z4"
|
||||||
|
<strong>输出:</strong>["3z4", "3Z4"]
|
||||||
|
|
||||||
|
<strong>输入:</strong>S = "12345"
|
||||||
|
<strong>输出:</strong>["12345"]
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>提示:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>S</code> 的长度不超过<code>12</code>。</li>
|
||||||
|
<li><code>S</code> 仅由数字和字母组成。</li>
|
||||||
|
</ul>
|
||||||
|
<div><div>Related Topics</div><div><li>位运算</li><li>字符串</li><li>回溯</li></div></div>\n<div><li>👍 282</li><li>👎 0</li></div>
|
Loading…
Reference in New Issue
Block a user