0

Help with string reverse

Don't know where I'm going wrong here. Any help would be appreciated. https://code.sololearn.com/cZdFjiQq6oD6/?ref=app

2nd Nov 2021, 8:58 AM
Ciaran Kelly
Ciaran Kelly - avatar
6 Answers
+ 1
You are complicating the code by introducing a new list. You have a string which needs to be reversed, and a piece of code which will iterate through that string in reverse. Why not just print out the letters as the code iterates for(int i=arr.length-1; i>=0; i--){ System.out.print(arr[i]); }
2nd Nov 2021, 9:28 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 2
This part: for(int i = arr.length-1; i >=0; i--)
2nd Nov 2021, 9:06 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 1
Rik Wittkopp I edited it and it seems to work perfectly. However there are two hidden test cases that are coming up wrong.
2nd Nov 2021, 9:13 AM
Ciaran Kelly
Ciaran Kelly - avatar
+ 1
Yeah you're right that's far simpler.
2nd Nov 2021, 9:39 AM
Ciaran Kelly
Ciaran Kelly - avatar
+ 1
I am a simple man đŸ€ŁđŸ˜‚
2nd Nov 2021, 9:39 AM
Rik Wittkopp
Rik Wittkopp - avatar
0
That worked perfectly thanks for the help! Simpler is always better idk why I thought I needed to store all the characters first haha
2nd Nov 2021, 9:42 AM
Ciaran Kelly
Ciaran Kelly - avatar