Reverse words in sentence
in:
“Let’s take LeetCode contest”
Out:
“s’teL ekat edoCteeL tsetnoc”
def reverseWords(self, s):
“””
:type s: str
:rtype: str
“””
words = s.split()
words = [word[::-1] for word in words]
return " ".join(words)two-sum:
Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target.
Whats the syntax of declaring an empty tuple, list, etc
two pointers:
left, right = 0, len(ary) - 1
while left < right:
if ary[right] is 0:
ary[:0] = [ary.pop(right)]
left += 1
else:
right -= 1
return aryGiven an integer x, return true if x is a
palindrome
, and false otherwise.