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 ...
随机推荐
- js中的extend
js中的extend 1. JS中substring与substr的区别 之前在项目中用到substring方法,因为C#中也有字符串的截取方法Substring方法,当时也没有多想就误以为 ...
- 【Visual Studio】解决方案未保存,请先保存你的解决方案,然后再管理Nuget包
上网下的Demo,文件夹中没有.sln文件,用VS打开.csproj文件来打开方案.此时可能因为一些引用问题想打开Nuget包管理器,会弹出如下提示: 解决方案未保存,请先保存你的解决方案,然后再管理 ...
- elasticsearch安装与使用(4)-- 安装中文分词插件elasticsearch 的 jdbc
前言 elasticsearch(下面简称ES)使用jdbc连接mysql比go-mysql-elasticsearch的elasticsearch-river-jdbc能够很好的支持增量数据更新的问 ...
- centsos各个版本的区别
CentOS-7.0-1406-x86_64-DVD.iso 标准安装版,一般下载这个就可以了CentOS-7.0-1406-x86_64-NetInstall.iso ...
- DataGridView使用技巧十:单元格表示值的自定义
通过CellFormatting事件,可以自定义单元格的表示值.(比如:值为Error的时候,单元格被设定为红色) 示例: private void dgv_Users_CellFormatting( ...
- 查看nginx cache命中率
一.在http header上增加命中显示 nginx提供了$upstream_cache_status这个变量来显示缓存的状态,我们可以在配置中添加一个http头来显示这一状态,达到类似squid的 ...
- UC浏览器调试移动端网站
准备工作: UC浏览器开发版网址 UC浏览器开发者版下载地址 下载adb_tool 步骤: 1.将adb_tool解压,把里面的文件复制到 C:\Windows\SysWOW64 文件夹下面. 2.运 ...
- C++ GDI+调用
封装了一个GDI+的使用类 GdiPluss.h #pragma once #include <comdef.h> #include <gdiplus.h> using nam ...
- e659. 缩放,剪取,移动,翻转图形
AffineTransform tx = new AffineTransform(); tx.scale(scalex, scaley); tx.shear(shiftx, shifty); tx.t ...
- 基本上每个应用程序领域的程序员都有使用 C++
C++ 的使用基本上每个应用程序领域的程序员都有使用 C++. C++ 通常用于编写设备驱动程序和其他要求实时性的直接操作硬件的软件. C++ 广泛用于教学和研究. 任何一个使用苹果电脑或 Windo ...