Iliiazbek Akhmedov
BAN USERmy email: ssymbol.1993@gmail.com
Actually the last loop is needed, since the value can be lower than 3 as well as more than 3, on top of that it might be not a single number, but bunch of them.
- Iliiazbek Akhmedov July 22, 2015I would simply use StringBuilder to avoid overhead of copying strings implicitly, and rather cut the tail by finding the last dir in the StringBuilder and return the result as StringBuilder.toString()...
Pseudo:
StringBuilder np = new SringBuilder();
String token = null;
int pos = 0;
while(null != (token = getToken(pos, path)) {
if(token.equals("..")) {
np.setLength(np.lastIndexOf("/")); //something like that
} else {
np.append(token + "/");
}
pos += token.length();
}
np.setLength(np.length() - 1); //remove redundant '/'
return np.toString();
You are missing the meaning of /../
For example, if we have path dir1/dir2/../dir3, the result should be dir1/dir3, while yours will simply be dir1/dir2/dir3
I agree with this answer too, since there can be a storage limitation, so, we can do in-place sorting.
- Iliiazbek Akhmedov July 22, 2015