LeetCode Reverse String Solution Explained - Java

preview_player
Показать описание


Preparing For Your Coding Interviews? Use These Resources
————————————————————

Other Social Media
----------------------------------------------

Show Support
------------------------------------------------------------------------------

#coding #programming #softwareengineering
Рекомендации по теме
Комментарии
Автор

the equal check is unnecessary in (a_pointer<=b_pointer), it would be sufficient to check a_pointer<b_pointer

ahmedhussam
Автор

You rock dude. Helping me so much in learning these algorithms.

nikob
Автор

Can't the condition be just while(a_pointer < b_pointer)? No sense to "swap" the same index with itself. Also the +=1 and -=1 could just be preincrement (++x) and predecrement (--x), though a halfway decent compiler should convert these to increments anyway (not sure about leetCode).

Gideon_Judges
Автор

1:11 took me so long to understand this part till I came across your video. Thanks

MiguelMartinez-yjyu
Автор

how tf is this rated as easy but I had to come to this video for the solution

MrGilly
Автор

This isn’t reversing a string this is reversing an array

nobodythenobody
Автор

It was meant to be solved using recusion.

abhishekmaurya
Автор

There is no print or return so how the char actually print?

navyaswarup
Автор

Thank you for the simple explanation.
I was able to solve it in the Leetcode compiler. But when I use the playground to write the complete program, in my main method I cannot declare the char array like this:
char[] s = ["h", "e", "l", "l", "o"]; //obviously the wrong way to declare a char array

And I cannot get the output to print the expected format: ["o", "l", "l", "e", "h"]

harisbijli
Автор

is it possible to use a StringBuilder or Buffer and then use the reverse method?

Maria-zgyd