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. mysql出现The total number of locks exceeds the lock table size解决办法

    mysql命令行下查看show variables like 'innodb_buffer_pool_size'; 修改innodb_buffer_pool_size值: windows下面 my.i ...

  2. sqlserver中sp_executesql使用实例(获取动态sql输出结果)

    语法 sp_executesql [ @stmt = ] stmt [     {, [@params=] N'@parameter_name data_type [ [ OUT [ PUT ][,. ...

  3. Android开发日记(三)

    protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentV ...

  4. Java中数据库连接池原理机制的详细讲解

    连接池的基本工作原理 1.基本概念及原理 由上面的分析可以看出,问题的根源就在于对数据库连接资源的低效管理.我们知道,对于共享资源,有一个很著名的设计模式:资源池(Resource Pool).该模式 ...

  5. 应用层timer_libc_posix timer

    应用层除了通过setitimer/getitimer设置获取timer外,还可通过timer_create()等一系列函数实现应用层timer功能. 应用流程 The timers created b ...

  6. WF追忆

    前一阵子学习了一下工作流,现在写个总结记录一下这个过程.要弄工作流,首先就要有个界面来画图,做web的,没办法,只能选择javascript和silverlight,找来找去,最后用了Shareide ...

  7. @RequestMapping @ResponseBody 和 @RequestBody 注解的用法与区别

    1.@RequestMapping 国际惯例先介绍什么是@RequestMapping,@RequestMapping 是一个用来处理请求地址映射的注解,可用于类或方法上.用于类上,表示类中的所有响应 ...

  8. 网络配置vlan

    1. # This file describes the network interfaces available on your system # and how to activate them. ...

  9. mysql 分库分表(水平切割和垂直切割)

    分表是分散数据库压力的好方法. 分表,最直白的意思,就是将一个表结构分为多个表,然后,可以再同一个库里,也可以放到不同的库. 当然,首先要知道什么情况下,才需要分表.个人觉得单表记录条数达到百万到千万 ...

  10. Java打印整数的二进制表示(代码与解析)

    Java打印整数的二进制表示(代码与解析) int a=-99; for(int i=0;i<32;i++){ int t=(a & 0x80000000>>>i)&g ...