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的更多相关文章

  1. 28. 字符串的全排列之第2篇[string permutation with repeating chars]

    [本文链接] http://www.cnblogs.com/hellogiser/p/string-permutation-with-repeating-chars.html [题目] 输入一个字符串 ...

  2. String Permutation

    Given two strings, write a method to decide if one is a permutation of the other. Example abcd is a ...

  3. 211. String Permutation【LintCode by java】

    Description Given two strings, write a method to decide if one is a permutation of the other. Exampl ...

  4. string中的substr() 和 find() 函数

    string问题中经常遇到在stringA中查找stringB,主要通过substr()跟find()来完成 substr().find().replace() 都可以用一个位置加上一个长读去描述子串 ...

  5. [Locked] Palindrome Permutation I & II

    Palindrome Permutation I Given a string, determine if a permutation of the string could form a palin ...

  6. Permutation Sequence LT60

    The set [1,2,3,...,n] contains a total of n! unique permutations. By listing and labeling all of the ...

  7. MySQL Workbench 8.0 目录汉化

    <?xml version="1.0"?> <data> <value type="list" content-type=&quo ...

  8. 【MySQL】MySQL Workbench 8.0 CE 界面汉化

    汉化前: 找到这个文件: 打开文件,复制下面这段替换进去保存,重新打开软件即可:(*改之前备份一下) <?xml version="1.0"?> <data> ...

  9. [LintCode]——目录

    Yet Another Source Code for LintCode Current Status : 232AC / 289ALL in Language C++, Up to date (20 ...

随机推荐

  1. js冒泡事件

    一.什么是事件冒泡 在一个对象上触发某类事件(比如单击onclick事件),如果此对象定义了此事件的处 理程序,那么此事件就会调用这个处理程序,如果没有定义此事件处理程序或者事件返回true,那么这个 ...

  2. Linux RPM 命令参数使用详解 查看 rpm包依赖性

    转载自:http://blog.csdn.net/deutschester/article/details/6309521 rpm 执行安装包 二进制包(Binary)以及源代码包(Source)两种 ...

  3. loadrunner11 测试restful

    loadrunner不知道为啥会有这么大的体积. 一开始用的是c脚本,可是恶心的是又不是完全的c,读文件的fseek居然没有. 后来又折腾java脚本,发现loadrunner11 java要用jdk ...

  4. 【WPF】CommandParameter解决多传参问题

    方法一:传参按钮控件自身绑定的ItemSource 用WAF框架实现MVVM,按钮的点击事件都要通过Command来传递到这个View对应的ViewModel上,再通过ViewModel传递到上层的C ...

  5. Json转list,两种包,两种方式

    1.使用fastjson 对于json串大小写没什么要求,测试的时候,我把javaBean属性设置成和json串一样的大小写,代码如下: package com.myTest.json.test1; ...

  6. SpringAOP来监控service层中每个方法的执行时间

    使用AOP来说,太方便了,并且特别适合这类场景. 代码如下,这里是将要统计的信息写到log文件中,也可以设计成写入表中. package com.ecsoft.interceptor; import ...

  7. [转]eclipse导入V7包出现错误解决办法

    android下v4    v7   v21等包是android系统的扩展支持包,就想windows的系统补丁一个道理. android的扩展包主要是用来兼容低版本的,比如android3.0以后出现 ...

  8. synchronize模块

    synchronize模块 使用rsync同步文件,其参数如下: archive: 归档,相当于同时开启recursive(递归).links.perms.times.owner.group.-D选项 ...

  9. android 创建 xml文件

    android创建xml文件的方法. 要操作android的外部存储,所以要在AndroidManifest.xml文件中添加权限. <uses-permission android:name= ...

  10. pyqt二进制和图片的转换

    参考:http://blog.chinaunix.net/uid-28194872-id-3516936.html MySQL数据库要想插入图片,其字段需要是BLOB类型.BLOB (binary l ...