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. Django 缓存、信号

    Reference: http://www.cnblogs.com/lianzhilei/p/6365877.html 缓存 由于Django是动态网站,所有每次请求均会去数据进行相应的操作,当程序访 ...

  2. HTML——如何在html中插入视频

    1,插入优酷视频: 在优酷分享界面有个html代码,直接复制放入body中,定义div的align居中即可 2.插入本地视频:用video属性  用mp4格式 <video>标签的属性 s ...

  3. java中静态方法的使用

    JAVA中使用静态方法 编程时我们心里一定要清楚静态方法和类的非静态方法方法的区别: 最根本区别从编译角度来说吧: 1) 静态(static)方法是编译时直接加载加载到内存中(离cpu最近的一块内存区 ...

  4. JVM 详谈

    JVM 详谈 本来这次应该讲讲ORM 的几个框架,但是笔者还没有完全总结出来,所以这里先插入一次学习JVM的心得.作为一个Java程序员,如果不了解JVM的工作原理,就很难从底层去把 握Java语言和 ...

  5. [Django学习]入门

    1. 搭建开发环境 安装django 建议安装1.8.2版本,这是一个稳定性高.使用广.文档多的版本 pip install django==1.8.2 查看版本:进入python shell,运行如 ...

  6. NTP原理

    ntp原理与设置 原创                     2016年09月17日 15:28:16                 标签: ntp / 原理 / 设置 / linux / 时钟同 ...

  7. [从jQuery看JavaScript]-注释(comments)

    jQuery片段: /*! * jQuery JavaScript Library v1.3.2 * http://jquery.com/ * * Copyright (c) 2009 John Re ...

  8. jquery json解析详解

    我们先以解析上例中的comments对象的JSON数据为例,然后再小结jQuery中解析JSON数据的方法. JSON数据如下,是一个嵌套JSON: 1 {"comments":[ ...

  9. 20个优秀的JavaScript 键盘事件处理库

    键盘事件是 Web 开发中最常用的事件之一,通过对键盘事件的捕获和处理可以提高网站的易用性和交互体验.下面,我们向大家介绍收集的20款优秀的 JavaScript 键盘事件处理库,帮助开发人员轻松处理 ...

  10. QSignalMapper类处理多信号关联同一个槽的方法(1)

    QSignalMapper这个类并不是个新鲜概念, 早在Qt2里就已经存在, 而且它的功能也是始终如一. 不过由于宣传力度不够(例子里涉及到它的很少)了解这个类人可能还不是很多, 所以特此撰文介绍此类 ...