GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — leetcode/java/784_Letter_Case_Permutation.java at master · pramodrj07/leetcode Expand file tree/ Copy path784_Letter_Case_Permutation.javaMore file actions 54 lines (46 loc) · 1.63 KB / Copy path784_Letter_Case_Permutation.javaFile metadata and controls54 lines (46 loc) · 1.63 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 class Solution { public List<String> letterCasePermutation(String S) { List<StringBuilder> ans = new ArrayList(); ans.add(new StringBuilder()); for (char c: S.toCharArray()) { int n = ans.size(); if (Character.isLetter(c)) { for (int i = 0; i < n; ++i) { ans.add(new StringBuilder(ans.get(i))); ans.get(i).append(Character.toLowerCase(c)); ans.get(n + i).append(Character.toUpperCase(c)); } } else { for (int i = 0; i < n; ++i) ans.get(i).append(c); } } List<String> finalans = new ArrayList(); for (StringBuilder sb: ans) finalans.add(sb.toString()); return finalans; } /*public List<String> letterCasePermutation(String S) { int B = 0; for (char c: S.toCharArray()) if (Character.isLetter(c)) B++; List<String> ans = new ArrayList(); for (int bits = 0; bits < 1<<B; bits++) { int b = 0; StringBuilder word = new StringBuilder(); for (char letter: S.toCharArray()) { if (Character.isLetter(letter)) { if (((bits >> b++) & 1) == 1) word.append(Character.toLowerCase(letter)); else word.append(Character.toUpperCase(letter)); } else { word.append(letter); } } ans.add(word.toString()); } return ans; }*/ } |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |