784:字母大小写全排列(未完成)

This commit is contained in:
huangge1199@hotmail.com 2021-07-19 10:40:58 +08:00
parent c26668abd4
commit 2e3ca5156b
2 changed files with 96 additions and 0 deletions

View 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)
}

View File

@ -0,0 +1,24 @@
<p>给定一个字符串<code>S</code>,通过将字符串<code>S</code>中的每个字母转变大小写,我们可以获得一个新的字符串。返回所有可能得到的字符串集合。</p>
<p>&nbsp;</p>
<pre><strong>示例:</strong>
<strong>输入:</strong>S = &quot;a1b2&quot;
<strong>输出:</strong>[&quot;a1b2&quot;, &quot;a1B2&quot;, &quot;A1b2&quot;, &quot;A1B2&quot;]
<strong>输入:</strong>S = &quot;3z4&quot;
<strong>输出:</strong>[&quot;3z4&quot;, &quot;3Z4&quot;]
<strong>输入:</strong>S = &quot;12345&quot;
<strong>输出:</strong>[&quot;12345&quot;]
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>S</code>&nbsp;的长度不超过<code>12</code></li>
<li><code>S</code>&nbsp;仅由数字和字母组成。</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>