class Solution {
static String revStr(String s) {
String ans = "";
for(int i = s.length()-1; i >= 0; i--) {
ans += s.charAt(i);
}
return ans;
}
}
I was solving a question to reverse a string and my output was correct, but it was taking longer than expected, and I can’t figure out how to optimise this code.
New contributor
ALZATO FF is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.