public class PrintEncoding {
public static void main(String[] args) {
String str = "655196";
printEncodings(str, "");
}
public static void printEncodings(String str, String ans) {
if (str.length() == 0) {
System.out.println(ans);
return;
}
// left path
int n = str.charAt(0) - '0';
if (n == 0)
return;
printEncodings(str.substring(1), ans + (char) ('a' + n - 1));
// rigth path
if (str.length() > 1) {
n = Integer.parseInt(str.substring(0, 2));
if (n <= 26) {
printEncodings(str.substring(2), ans + (char) ('a' + n - 1));
}
}
}
}
Wednesday, February 2, 2022
Print Encodings
Subscribe to:
Post Comments (Atom)
Diagonal Traversal
eg. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Output: 1 6 11 16 2 7 12 3 8 4 Approach:...
-
https://leetcode.com/problems/reverse-integer/description/ Integer.MAX_VALUE = 2,147,483,647 = 2 31 - 1 Integer.MIN_VALUE = -2,147,483,64...
-
https://leetcode.com/problems/two-sum/description/ Given the constraints: 2 <= nums.length <= 10⁴ -10⁹ <= nums[i] <= 10⁹ -10...
-
For this particular question, we only have the In - region. So, the code looks like : package pep.Day7 ; public class TowerOfHanoi { p...
No comments:
Post a Comment