Doubt:
Hello, I wanted to know the complexity of the following code:
It is O(nn). correct?
I thought reversing the string takes O(n) time and it is inside a for loop that runs for O(n) time. Therefore, the complexity is O(nn) . Please correct me if I am wrong. I struggle with finding the complextity, so thought should cross check my answer with others
Question:
Reverse Words in a String III
Input: s = "Let's take LeetCode contest"
Output: "s'teL ekat edoCteeL tsetnoc"
Answer:
class Solution:
def reverseWords(self, s: str) -> str:
wo1 = []
for word in s.split(" "):
wo1.append(word[::-1])
print(wo1)
return (' '.join(wo1))