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 ...
随机推荐
- [转]一步一步部署SSIS包图解教程
本文就SQL统计分析SSIS包的部署进行一次详细的部署图解教程,Sql Server Integration Services 提供了非常简单的部署工具,利用这些工具可以方便地将包文件(*.dtsx) ...
- BAT-使用BAT方法清理Delphi临时文件
@echo offdel /S *.~*del /S *.dcudel /S *.dskdel /S *.hppdel /S *.ddpdel /S *.mpsdel /S *.mptdel /S * ...
- [转] Fragment——startActivityForResult后onActivityResult无反应之问题总结
转自:http://m.blog.csdn.net/article/details?id=49507025 摘取片段如下 个人测试后的一些总结: 1.Fragment中直接使用startActivit ...
- 用Lucene对文档进行索引搜索
问题 现在给出很多份文档,现在对某个搜索词感兴趣,想找到相关的文档. 简单搜索 一种简单粗暴的做法是: 1.读取每个文档:2.找到其中含有搜索词的文档:3.对找到的文档中搜索词出现的次数统计:4.根据 ...
- DatagridView内容自动换行和换行符换行
内容自动换行: 在 DataGridView 新增 Row 时,設定 DataGridView 的 DefaultCellStyle 屬性WrapMode=true: 换行符换行: 在 DataGri ...
- HashMap与ConcurrentHashMap的区别<转>
从JDK1.2起,就有了HashMap,正如前一篇文章所说,HashMap不是线程安全的,因此多线程操作时需要格外小心. 在JDK1.5中,伟大的Doug Lea给我们带来了concurrent包,从 ...
- SpringAOP来监控service层中每个方法的执行时间
使用AOP来说,太方便了,并且特别适合这类场景. 代码如下,这里是将要统计的信息写到log文件中,也可以设计成写入表中. package com.ecsoft.interceptor; import ...
- jquery轮播控件
网上找了一个轮播控件,效果不错,而且很容易改,需要的同学去下载咯 地址是:http://download.csdn.net/detail/jine515073/7704143
- iOS开发小技巧--textField成为密码框,view加载完后textField获取焦点
文本框安全输入:Secure Text Entry(安全文本输入) view加载完后textField获取焦点的正确做法
- DataRowState、AcceptChanges、RejectChanges综合使用示例:实现DataGridView数据的增、删、改
下面的示例中,通过一个程序,演示使用DataRowState.AcceptChanges.RejectChanges,实现DataGridView数据的增.删.改. 一.界面设计 二.代码实现 usi ...