[leetcode-784-Letter Case Permutation]
Given a string S, we can transform every letter individually to be lowercase or uppercase to create another string. Return a list of all possible strings we could create.
Examples:
Input: S = "a1b2"
Output: ["a1b2", "a1B2", "A1b2", "A1B2"] Input: S = "3z4"
Output: ["3z4", "3Z4"] Input: S = "12345"
Output: ["12345"]
Note:
S
will be a string with length at most12
.S
will consist only of letters or digits.
思路:
深度优先遍历。
void dfs (vector<string>& ret,string S,int i)
{
if(i >= S.length())
{
ret.push_back(S);
return;
} if(isalpha(S[i]))
{
S[i] = tolower(S[i]);
dfs(ret,S,i+); S[i] = toupper(S[i]);
dfs(ret,S,i+);
}
else dfs(ret,S,i+); }
vector<string> letterCasePermutation(string S)
{
vector<string> ret;
dfs(ret,S,);
return ret;
}
参考:
https://leetcode.com/problems/letter-case-permutation/discuss/117180/clean-C++-solution.
[leetcode-784-Letter Case Permutation]的更多相关文章
- 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 ...
- LeetCode 784 Letter Case Permutation 解题报告
题目要求 Given a string S, we can transform every letter individually to be lowercase or uppercase to cr ...
- 【Leetcode_easy】784. Letter Case Permutation
problem 784. Letter Case Permutation 参考 1. Leetcode_easy_784. Letter Case Permutation; 2. Grandyang; ...
- 【LeetCode】784. Letter Case Permutation 解题报告 (Python&C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 回溯法 循环 日期 题目地址:https://leet ...
- [LeetCode&Python] Problem 784. Letter Case Permutation
Given a string S, we can transform every letter individually to be lowercase or uppercase to create ...
- 784. Letter Case Permutation 字符串中字母的大小写组合
[抄题]: Given a string S, we can transform every letter individually to be lowercase or uppercase to c ...
- 784. Letter Case Permutation C++字母大小写全排列
网址:https://leetcode.com/problems/letter-case-permutation/ basic backtracking class Solution { public ...
- 【easy】784. Letter Case Permutation
Examples: Input: S = "a1b2" Output: ["a1b2", "a1B2", "A1b2", ...
- 784. Letter Case Permutation
这个题的思想很重要,两种方法 第一种,回溯法 class Solution { public: int sz; vector<string> letterCasePermutation(s ...
- LeetCode算法题-Letter Case Permutation(Java实现)
这是悦乐书的第315次更新,第336篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第184题(顺位题号是784).给定一个字符串S,将每个字母单独转换为小写或大写以创建另 ...
随机推荐
- mongo配置项说明
mongo configure 配置文件 storage: dbPath: mongod实例存储其数据的目录. indexBuildRetry: 指定是否mongod在下次启动时重 ...
- WEB中需求分析应该考虑的问题
一. 针对用户群体要考虑因素 1.用户年龄 2.选择素材 3.网站布局 4.颜色搭配 5. 用户体验及动效 6.功能便捷 用户需求.用户兴趣爱好.性格.职业.教育水平高低.消费观念.PC端和移动端哪一 ...
- php 算法(二分法)只适用于有序表,且限于顺序存储结构
function demo($array,$low,$high,$k){ if($low<=$high){//判断该数组是否存在 $mid = intval(($low+$high)/2 ); ...
- sourcetree .git 强制忽略指定文件不提交
在公司写项目,大部分都会用到 svn 或 git 提交代码到服务器.我们公司用的GIT,每个程序员有自己的独立分支,各写各的代码互不冲突,最终合并到主分支再解决相同代码冲突问题.这时候会遇到一些配置文 ...
- C语言学习记录_2019.02.04
逻辑性变量的定义符:bool,在C语言中只有true和false: 定义方式:bool t = true; 逻辑运算符: !:逻辑非 &&:逻辑与 ||:逻辑或 表达区间的错误形式:4 ...
- (杭电2053)A + B Again(转换说明符)
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): ...
- Linux字符设备驱动--No.1
平台:tiny210SOC:s5pv210内核:Linux 3.0.8字符驱动:按键中断驱动源码: /************************************************* ...
- GeekOS: 一、构建基于Ubuntu9.04的实验环境
参考:http://www.cnblogs.com/wuchang/archive/2009/05/05/1450311.html 补充:在最后步骤中,执行bochs即可弹出运行窗口
- 汇编中resb这样的指令是什么意思?
转载下来,方便以后查看 原作网址:http://blog.csdn.net/m1j2t3/article/details/5681657 汇编中resb这样的指令是什么意思? 还有我在汇编程序中看到这 ...
- C# WebBrowser的DrawToBitmap方法 截取网页保存为图片
bool mark = true; private void btnOpen_Click(object sender, EventArgs e) { ...