-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReturnStringCodes.java
More file actions
39 lines (31 loc) · 992 Bytes
/
Copy pathReturnStringCodes.java
File metadata and controls
39 lines (31 loc) · 992 Bytes
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
public class ReturnStringCodes {
public static String[] stringCodes(String s,String temp, String[] ans){
if (s.length()==0){
ans = array(ans);
ans[ans.length-1] = temp;
return ans;
}
ans = stringCodes(s.substring(1),temp + (char)convert(s.substring(0,1)),ans);
if (s.length() >= 2){
int t = convert(s.substring(0,2));
if (t != 0){
ans = stringCodes(s.substring(2),temp + (char)t, ans);
}
}
return ans;
}
public static int convert (String str){
int t = Integer.parseInt(str);
if (t < 27 && t > 0){
return t + 96;
}
return 0;
}
public static String[] array(String[] arr){
String[] tempArr = new String[arr.length+1];
for (int i = 0; i < arr.length; i ++){
tempArr[i] = arr[i];
}
return tempArr;
}
}