[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,将每个字母单独转换为小写或大写以创建另 ...
随机推荐
- 用Jquery控制元素的上下移动 实现排序功能
在页面上,控制元素上下移动,进行排序是我们比较常用的功能,今天我用jQuery 写个 简单方便,功能齐全的实现方式. 话不多说,直接上代码,下面是基础的引入jq和html元素部分: <scrip ...
- jQuery表单验证的几种方法
1.jQuery的框架的验证:validate框架 Jquery Validate 验证规则 (1)required:true 必输字段(2)remote:”check.PHP” 使用ajax方法调用 ...
- 分页插件pagehelper ,在sql server 中是怎么配置的
<configuration> <plugins> <!-- com.github.pagehelper为PageHelper类所在包名 --> <plugi ...
- Vue性能优化之组件按需加载(以及一些常见的性能优化方法)
关于Vue中的按需加载我就简单介绍一下:大概就是我们所有的东西都会在app.js里面,但是我们并不需要把所有的组件都一次性加载进来,我们可以在需要它的时候再将它加载进来,话不多说,开车! 1.webp ...
- javascript实现复选框单选多选!
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- MySQL数据库的原理
点进去就是你历经千辛万苦找到的数据库的原理: https://www.cnblogs.com/smallyard/p/5626061.html
- Python中的封装,继承和多态
面向对象的三大特性:封装,继承和多态 封装:在类的内部定义属性和方法,通过对象或类名来访问属性和方法,隐藏功能的实现细节,也可以设置访问权限. 广义的封装:实例化一个对象,给对象空间封装一些属性:狭义 ...
- Facebook 被指收集用户数据:通过照片和文本
北京时间5月25日消息,在加利福尼亚州进行的对Facebook泄露用户信息一案中,法院对Facebook提起一项新的诉讼,指控该公司通过App收集了用户及他们朋友的信息. 上周向加利福尼亚州圣马特奥市 ...
- rtsp over tcp并设置多个options
版权声明:本文为博主原创文章,未经博主允许不得转载. var vlc=document.getElementById("vlc"); var options = new Array ...
- Qt——styleSheet
1.两个地方调用 QWidget::setStyleSheet() QApplication::setStyleSheet() 2.基本语法 selector {attribute : value} ...