string permutation with upcase and lowcase
Give a string, which only contains a-z. List all the permutation of upcase and lowcase.
For example, str = "ab", the output should be
"ab", "aB", "Ab", "AB"
for str = "abc", the output should be
"abc", "abC", "aBc", "aBC", "Abc", "AbC", "ABc", "ABC"
[解题思路]
本题与其他permutation题目区别在于结果中每位的字符都是固定的,仅仅是大小写的区别
因而不需要循环来遍历,使字符串的每一位可以遍历任意一个值
public class Solution {
public static void main(String[] args) {
List<String> result = new ArrayList<String>();
String tmp = "";
permutation(tmp, 0, 4, result);
System.out.println(result);
}
private static void permutation(String tmp, int depth, int len,
List<String> result) {
if (depth == len) {
result.add(tmp);
return;
} tmp += (char) ('a' + depth);
permutation(tmp, depth + 1, len, result);
tmp = tmp.substring(0, tmp.length() - 1); tmp += (char) ('A' + depth);
permutation(tmp, depth + 1, len, result);
tmp = tmp.substring(0, tmp.length() - 1); }
}
string permutation with upcase and lowcase的更多相关文章
- 28. 字符串的全排列之第2篇[string permutation with repeating chars]
[本文链接] http://www.cnblogs.com/hellogiser/p/string-permutation-with-repeating-chars.html [题目] 输入一个字符串 ...
- String Permutation
Given two strings, write a method to decide if one is a permutation of the other. Example abcd is a ...
- 211. String Permutation【LintCode by java】
Description Given two strings, write a method to decide if one is a permutation of the other. Exampl ...
- string中的substr() 和 find() 函数
string问题中经常遇到在stringA中查找stringB,主要通过substr()跟find()来完成 substr().find().replace() 都可以用一个位置加上一个长读去描述子串 ...
- [Locked] Palindrome Permutation I & II
Palindrome Permutation I Given a string, determine if a permutation of the string could form a palin ...
- Permutation Sequence LT60
The set [1,2,3,...,n] contains a total of n! unique permutations. By listing and labeling all of the ...
- MySQL Workbench 8.0 目录汉化
<?xml version="1.0"?> <data> <value type="list" content-type=&quo ...
- 【MySQL】MySQL Workbench 8.0 CE 界面汉化
汉化前: 找到这个文件: 打开文件,复制下面这段替换进去保存,重新打开软件即可:(*改之前备份一下) <?xml version="1.0"?> <data> ...
- [LintCode]——目录
Yet Another Source Code for LintCode Current Status : 232AC / 289ALL in Language C++, Up to date (20 ...
随机推荐
- 在linux命令行输出颜色
示例: #include <stdio.h> int main() { printf("\e[31;1m Hello, world! \e[0m\n"); } 也就是说 ...
- javaee 架构师之路
Java程序员 高级特性 反射.泛型.注释符.自动装箱和拆箱.枚举类.可变 参数.可变返回类型.增强循环.静态导入 核心编程 IO.多线程.实体类. 集合类.正则表达式. XML和属性文件 图形编程 ...
- c++之五谷杂粮4---explicit
4.1在要求隐式转换的程序上下文中,我们可以通过将构造函数声明为explicit加以阻止. 关键字explicit只对一个实参的构造函数有效.需要多个实参的构造函数不能用于执行隐式转换,所以无需将这些 ...
- Java SerialPort SDK
SerialPort SDK is a professional java serial port SDK,provides simple communication interface to con ...
- 【Unity笔记】鼠标射线由指定层接收
LayerMask mask = << LayerMask.NameToLayer("UI"); Ray ray = Camera.main.ScreenPointTo ...
- svg 添加超链接
<svg> <a xlink:href="http://www.w3.org//Graphics//SVG//Overview.htm8"> ...
- Js加密与解密
<html><head><META HTTP-EQUIV="MSThemeCompatible" CONTENT="Yes"> ...
- 浅谈 JavaScript 编程语言的编码规范
对于熟悉 C/C++ 或 Java 语言的工程师来说,JavaScript 显得灵活,简单易懂,对代码的格式的要求也相对松散.很容易学习,并运用到自己的代码中.也正因为这样,JavaScript 的编 ...
- Hadoop集群作业调度算法
转自:http://blog.csdn.net/chen_jp/article/details/7983076 Hadoop集群中有三种作业调度算法,分别为FIFO,公平调度算法和计算能力调度算法 先 ...
- 联合主键用hibernate注解映射方式主要有三种:
将联合主键的字段单独放在一个类中,该类需要实现java.io.Serializable接口并重写equals和hascode 第一.将该类注解为@Embeddable,最后在主类中(该类不包含联合主键 ...