Загрузка...

#day3 557. Reverse Words in a String III Leetcode problem | Optimized solution

Leetcode question: https://leetcode.com/problems/reverse-words-in-a-string-iii/
#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'.......

Видео #day3 557. Reverse Words in a String III Leetcode problem | Optimized solution канала RCTECHLIFE
Яндекс.Метрика
Все заметки Новая заметка Страницу в заметки
Страницу в закладки Мои закладки
На информационно-развлекательном портале SALDA.WS применяются cookie-файлы. Нажимая кнопку Принять, вы подтверждаете свое согласие на их использование.
О CookiesНапомнить позжеПринять