Leetcode question: leetcode.com/p...
#leetcode #75hardchallenge #day3 #faang #maang #google
Reverse Words in a String III :
Approach:
1. Using two pointers, 'start' and 'end', each time 'end' reaches a space, we reverse the words before.
2. To reverse, we convert the String 's' to a char array, then write a method to reverse the char in the array.
1. Convert s into char array.
2. take a loop
3. When 'end' reaches a space character ' ', reverse the words from 'start' to 'end' - 1 index in 'chars'.
4. reset the start for the next word.
Example
s = "Let's take LeetCode contest"
char ch= 'l','e','t'.......
3 окт 2024