Skip to content
Merged

Setup #162

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions algorithms_project/algorithms/arrays/two_pointer.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
class Solution:
def reverseWords_manual(s):
def reverseWords_manual(string_word):
res = ''
left, r = 0, 0
left, right = 0, 0

while r < len(s):
if s[r] != ' ':
r += 1
while right < len(string_word):
if string_word[right] != ' ':
right += 1
else:
res += s[left:r+1][::-1]
r += 1
left = r
res += string_word[left:right+1][::-1]
right += 1
left = right

res += ' '
res += s[left:r + 2][::-1]
res += string_word[left:right + 2][::-1]
return res[1:]


Expand All @@ -32,10 +32,10 @@ def reverserWords(s):
class Solution3:
def reverseWords_manual1(s):
res = ''
for r in range(len(s) + 1):
if r == len(s) or s[r] == ' ':
res += s[:r][::-1]
if r < len(s):
for right in range(len(s) + 1):
if right == len(s) or s[right] == ' ':
res += s[:right][::-1]
if right < len(s):
res += ' '
return res

Expand Down
Empty file.
11 changes: 11 additions & 0 deletions algorithms_project/tests/test_arrays/test_two_pointer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import pytest
from algorithms.arrays.two_pointer import Solution


@pytest.mark.parametrize("input_str,expected", [
("rac tar", "car rat"),
("Hello World", "olleH dlroW"),
("Python", "nohtyP"),
])
def test_reverse_words(input_str, expected):
assert Solution.reverseWords_manual(input_str) == expected
Loading