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正则表达式判断一个字符串是否是正确的有数字和小数点组成的金钱形式和 判读数值类型的正则表达式

    function checkRates(str){    var re = /^(([1-9][0-9]*\.[0-9][0-9]*)|([0]\.[0-9][0-9]*)|([1-9][0-9]*) ...

  2. pygame--颜色变化

    #_*_coding:utf-8_*_ import pygame from pygame.locals import * from sys import exit pygame.init() scr ...

  3. sql插入数据

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  4. Java中常见的异常__

    作为一名游戏开发者,程序员,很自然必须熟悉对程序的调试方法.而要调试程序,自然需要对程序中的常见的异常有一定的了解,这些日子很多朋友都提出了很多问题,都是关于游戏中的报错,因此在这里我将一些常见的程序 ...

  5. enter快捷键盘

    protected override bool ProcessDialogKey(Keys keyData) { #region PageDown if (keyData == Keys.Enter) ...

  6. idea中maven依赖不能下载的解决办法

    使用maven 命令 maven install 在项目所在文件夹 执行.

  7. 802.1q VLAN

    VLAN(Virtual Local Area Network),是一种通过将局域网内的设备逻辑地而不是物理地划分成一个个网段从而实现虚拟工作组的技术. 以一个网络接口为主设备,可以创建多个虚拟网络接 ...

  8. oops_根据epc定位linux_kernel_panic位置

    韩大卫@吉林师范大学 2014.12.10 转载请表明出处 ***************************************************** 关于内核报错 “Unable t ...

  9. CentOs6.5 安装rabbitmq(转)

    // 安装预环境 yum install gcc gcc-c++ yum install zlib zlin-devel ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 / ...

  10. JEECG常见问题大全征集

    大家还有什么问题.请跟帖,谢谢支持. .  JEECG常见问题大全征集 1. jeecg没有数据库脚本问题   jeecg不须要数据库脚本,在数据库创建好数据库.项目配置好数据源链接.会自己主动建表. ...