Two Sum

Using Loop

def twoSum(self, nums: List[int], target: int) -> List[int]:

for i in range(len(nums)):

for j in range(i+1, len(nums)):

if (target-nums[i])==nums[j]:

return[i,j]

Using Dictionary

def twoSum(self, nums: List[int], target: int) -> List[int]:

cmap=dict()

for i in range(len(nums)):

num=nums[i]

c=target-num # c=2

if num in cmap:

return[cmap[num],i]

else:

cmap[c]=i

Palindrome Number

def isPalindrome(self, x: int) -> bool:

rev=0

n=x

while(n!=0):

rem=n%10

rev=rev*10+rem

n= n//10

if(x==rev):

return True

else:

return False