Leetcode784.Letter Case Permutation字母大小写全排列
给定一个字符串S,通过将字符串S中的每个字母转变大小写,我们可以获得一个新的字符串。返回所有可能得到的字符串集合。
示例: 输入: S = "a1b2" 输出: ["a1b2", "a1B2", "A1b2", "A1B2"] 输入: S = "3z4" 输出: ["3z4", "3Z4"] 输入: S = "12345" 输出: ["12345"]
注意:
- S 的长度不超过12。
- S 仅由数字和字母组成。
class Solution {
public:
map<string, int> visit;
int len;
vector<string> res;
vector<string> letterCasePermutation(string S)
{
len = S.size();
DFS(S);
return res;
}
void DFS(string str)
{
visit[str] = 1;
res.push_back(str);
for(int i = 0; i < len; i++)
{
if(str[i] >= '0' && str[i] <= '9')
continue;
int x = 'a' - 'A';
char temp = str[i];
if(str[i] >= 'a' && str[i] <= 'z')
{
str[i] = str[i] - x;
}
else
{
str[i] = str[i] + x;
}
if(visit[str] == 1)
continue;
DFS(str);
str[i] = temp;
}
}
};
Leetcode784.Letter Case Permutation字母大小写全排列的更多相关文章
- [LeetCode] Letter Case Permutation 字母大小写全排列
Given a string S, we can transform every letter individually to be lowercase or uppercase to create ...
- 【Leetcode_easy】784. Letter Case Permutation
problem 784. Letter Case Permutation 参考 1. Leetcode_easy_784. Letter Case Permutation; 2. Grandyang; ...
- Java实现 LeetCode 784 字母大小写全排列(DFS)
784. 字母大小写全排列 给定一个字符串S,通过将字符串S中的每个字母转变大小写,我们可以获得一个新的字符串.返回所有可能得到的字符串集合. 示例: 输入: S = "a1b2" ...
- 784. Letter Case Permutation
这个题的思想很重要,两种方法 第一种,回溯法 class Solution { public: int sz; vector<string> letterCasePermutation(s ...
- [LeetCode] 784. 字母大小写全排列 ☆☆☆(回溯、深度优先遍历)
https://leetcode-cn.com/problems/letter-case-permutation/solution/shen-du-you-xian-bian-li-hui-su-su ...
- [Swift]LeetCode784. 字母大小写全排列 | Letter Case Permutation
Given a string S, we can transform every letter individually to be lowercase or uppercase to create ...
- 784. Letter Case Permutation C++字母大小写全排列
网址:https://leetcode.com/problems/letter-case-permutation/ basic backtracking class Solution { public ...
- 784. Letter Case Permutation 字符串中字母的大小写组合
[抄题]: Given a string S, we can transform every letter individually to be lowercase or uppercase to c ...
- leetcode 784. Letter Case Permutation——所有BFS和DFS的题目本质上都可以抽象为tree,这样方便你写代码
Given a string S, we can transform every letter individually to be lowercase or uppercase to create ...
随机推荐
- 数据表中记录明明有,session.get(类.class, id);返回null
出现null的处理思路首先检查数据库中是否真的有这个记录 确实存在的,用接口查一下最大值,也是存在的,数据库连接正常 写sql也可以查得到 然而诡异的事情出现了 难道是一直在用的dao代码出了问题? ...
- 【vue移动端架子】vue-h5-template
作者大大的地址:https://github.com/sunnie1992/vue-h5-template 我们运行项目,倒是可以看一看效果 虽然就是显示的UI,但是应该可以知道作者大大想要什么东西了 ...
- JAVA面试常见问题之数据库篇
1.MySQL 索引使用的注意事项 更新频繁的列不要加索引 数据量小的表不要加索引 重复数据多的字段不要加索引,比如性别字段 首先应该考虑对where 和 order by 涉及的列上建立索引 2.D ...
- 更改电脑用户名(可更改C:\Users\用户名)
参考:http://blog.csdn.net/zhang_jinhe/article/details/40624847 假设我们需要将帐户A改名为B. 首先我们需要用另一个管理员帐户C登陆系统. 1 ...
- Django项目:CRM(客户关系管理系统)--25--17PerfectCRM实现King_admin单列排序
登陆密码设置参考 http://www.cnblogs.com/ujq3/p/8553784.html {#table_data_list.html#} {## ————————08PerfectCR ...
- npm常用命令及版本号
npm 包管理器的常用命令 测试环境为node>=8.1.3&&npm>=5.0.3 1, 首先是安装命令 //全局安装 npm install 模块名 -g //本地安装 ...
- java并发系列(三)-----ReentrantLock(重入锁)功能详解和应用演示
1. ReentrantLock简介 jdk中独占锁的实现除了使用关键字synchronized外,还可以使用ReentrantLock.虽然在性能上ReentrantLock和synchronize ...
- iFrame 父子窗口通讯
今天就来说说 iFrame 的父子窗口通讯,关于 iFrame 这里就不陈述了,想要了解的盆友可以百度一下, 由于项目需要,前些天用到了个弹框框架 layer 弹出层,有很多弹出的方式,其中一种就是用 ...
- jQuery控制导航条样式
原理:点击当前元素时,当前元素添加(样式类),父辈的兄弟姐妹的孩子('a')去掉此样式类. 代码如下: /*次要导航*/ $(".subnav li a").click(funct ...
- hdu 1296 Polynomial Problem(多项式模拟)
Problem Description We have learned how to obtain the value of a polynomial when we were a middle sc ...