-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Open
Description
Bug Report for https://neetcode.io/problems/string-encode-and-decode
Please describe the bug below and include any steps to reproduce the bug or screenshots if possible.
I have written below code-
In the decode method- Line 'if(str.charAt(i) == '$'){' does not compile.
StringBuilder sb = new StringBuilder();
for(int i=0; i<strs.size(); i++){
String str = strs.get(i);
sb.append(str.length()+"$");
sb.append(str);
}
return sb.toString();
}
public List<String> decode(String str) {
List<String> list = new ArrayList<>();
int cursor=0;
int i = 0;
while(i < str.length()){
if(str.charAt(i) == '$'){
int length = Integer.parseInt(str.substring(cursor, i));
String originalToken = str.substring(i+1, i+1+length);
list.add(originalToken);
i = i + 1 + length;
cursor = i;
} else {
i++;
}
}
return list;
In
Metadata
Metadata
Assignees
Labels
No labels