Advertisement
rajeshinternshala

Untitled

Aug 12th, 2023
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.68 KB | None | 0 0
  1.  public static String decode(String encoded) {
  2.         StringBuilder sb = new StringBuilder(encoded);
  3.         String str = sb.reverse().toString();
  4.         StringBuilder ans = new StringBuilder();
  5.         int i = 0;
  6.         int num = 0;
  7.         while (i < str.length()) {
  8.             num = num * 10 + Integer.parseInt(str.charAt(i++) + "");
  9.             if (isInRange(num)) {
  10.                 char ch = (char) (num);
  11.                 ans.append(ch);
  12.                 num = 0;
  13.             }
  14.  
  15.         }
  16.         return ans.toString();
  17.     }
  18.  
  19.     private static boolean isInRange(int num) {
  20.         return (num >= 65 && num <= 90) || (num >= 97 && num <= 122) || (num == 32);
  21.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement