Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

557 Solved slow #25

Merged
merged 1 commit into from
Oct 1, 2023
Merged
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
35 changes: 35 additions & 0 deletions 557. Reverse Words in a String III/557.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
test_cases = [
"Let's take LeetCode contest",
"God Ding"
]

expected_results = [
"s'teL ekat edoCteeL tsetnoc",
"doG gniD"
]


class Solution:
def reverseWords(self, s):
list = s.split(" ")
new_list = []
for word in list:
new_word = ""
for letter in word:
new_word = letter + new_word
new_list.append(new_word)
new_string = " ".join(new_list)
return new_string


# Testing
for i in range(0, len(test_cases)):
print("==================================")
result = Solution.reverseWords(
Solution, test_cases[i])
if result == expected_results[i]:
print(f"==Test case {i+1} was valid")
print(f"✔️ Got '{result}', expected '{expected_results[i]}'")
else:
print(f"==Test case {i+1} was INVALID")
print(f"❌ Got '{result}', expected '{expected_results[i]}'")