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 ...
随机推荐
- [未解决]Ajax-读取并解析XML,动态生成select下拉列表框
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...
- .Net应该学什么怎么学(一)
更新时间:2012年06月05日18时21分 来源:传智播客.Net 上篇<学了.Net做什么开发>中我讲到了目前.Net开发主要方向是Web开发,因此在本篇中我将主要讲解做Web开发要学 ...
- Elasticsearch的javaAPI之get,delete,bulk
Elsasticsearch的javaAPI之get get API同意依据其id获得指定index中的基于json document.以下的样例得到一个JSON document(index为twi ...
- Tomcat性能优化之(一) 启动GZIP压缩
Tomcat性能优化之(一) 启动GZIP压缩 1:设置TOMCAT启用GZIP压缩,通过浏览器HTTP访问对应的资源会根据配置进行压缩. <Connector port="8080& ...
- openwrt内核配置选项添加
摘自:http://blog.csdn.net/weiniliuchao/article/details/50295527 增加内核配置选项 openwrt的.config文件中,关于内核的选项都是形 ...
- 官网下载到离线的Adobe Acrobat Reader DC
Adobe 官方 FTP :ftp://ftp.adobe.com/ Adobe Acrobat Reader DC 下载目录:ftp://ftp.adobe.com/pub/adobe/reader ...
- JVM监控添加参数
-Dcom.sun.management.jmxremote.port 远程主机端口号的-Dcom.sun.management.jmxremote ...
- Java-DBCP连接池
创建项目: 导入jar包: 参见上图. JDBCConn.java获取数据源类: package com.gordon.jdbcconn; import java.io.InputStream; im ...
- js学习笔记29----拖拽
原理:先计算鼠标与拖拽目标的左侧距离 跟 上面距离,再计算拖动后的位置. 示例代码: <!DOCTYPE html> <html lang="en"> &l ...
- Java打印整数的二进制表示(代码与解析)
Java打印整数的二进制表示(代码与解析) int a=-99; for(int i=0;i<32;i++){ int t=(a & 0x80000000>>>i)&g ...