Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static String decode(String encoded) {
- StringBuilder sb = new StringBuilder(encoded);
- String str = sb.reverse().toString();
- StringBuilder ans = new StringBuilder();
- int i = 0;
- int num = 0;
- while (i < str.length()) {
- num = num * 10 + Integer.parseInt(str.charAt(i++) + "");
- if (isInRange(num)) {
- char ch = (char) (num);
- ans.append(ch);
- num = 0;
- }
- }
- return ans.toString();
- }
- private static boolean isInRange(int num) {
- return (num >= 65 && num <= 90) || (num >= 97 && num <= 122) || (num == 32);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement