LeetCode 541 | Reverse String II | Algorithm Explained (Java)

preview_player
Показать описание
The description reads:
"Given a string and an integer k, you need to reverse the first k characters for every 2k characters counting from the start of the string. If there are less than k characters left, reverse all of them. If there are less than 2k but greater than or equal to k characters, then reverse the first k characters and left the other as original.
Input: s = "abcdefg", k = 2
Output: "bacdfeg"
"

Running Time: O(N)
Space Complexity: O(N)

FOLLOW ME:
Рекомендации по теме
Комментарии
Автор

Thanks for explaining the problem at 1:55.

jonc
Автор

You should explain the actual reason they are using the min method. What are they trying to accomplish exactly?

sanathboddhula
Автор

you didn't really explain the 'min' part...trickiest part, have no clue who comes up with that right away lol

georgebrooking