Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Find Case Combinations of a String
//'main' method must be in a class 'Rextester'. //Compiler version 1.8.0_111 import java.util.*; import java.lang.*; class Rextester { public static void main(String args[]) { String input = "aBc"; List<String> res = caseCombination(input); System.out.println(res); input = "AirBnb"; res = caseCombination(input); System.out.println(res + ", size: " + res.size()); assert 64 == res.size(); assert "airbnb" == res.get(0); assert "Airbnb" == res.get(1); assert "aIRBNB" == res.get(62); assert "AIRBNB" == res.get(63); } // Bit Manipulation private static List<String> caseCombination(String input) { List<String> res = new ArrayList<String>(); if(input == null || input.length() == 0) return res; int len = input.length(); char[] arr = input.toCharArray(); for(int i = 0; i < (1 << len); i++) { StringBuilder sb = new StringBuilder(); for(int j = 0; j < len; j++) { sb.append( (i >> j & 1) != 0 ? Character.toUpperCase(arr[j]) : Character.toLowerCase(arr[j])); } res.add(sb.toString()); } return res; } }
run
|
edit
|
history
|
help
0
BFS in graph
Problem: fb_series
Bubble Sort
1
javaLP(Multi)
"Naive" recursion vs. Dynamic Programming
Jagpreet Bajwa
Alphabets
javaClassAr2
1(D).