This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution: | |
def containsDuplicate(self, nums: List[int]) -> bool: | |
s=set(nums) | |
return len(nums)-len(s)>0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution: | |
def threeSum(self, nums: List[int]) -> List[List[int]]: | |
if len(nums)<3: | |
return [] | |
if len(nums)==3: | |
if sum(nums)==0: | |
return [nums] | |
else: | |
return [] | |
nums.sort() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution: | |
def singleNumber(self, nums: List[int]) -> int: | |
m={} | |
for i in nums: | |
if i not in m.keys(): | |
m[i]=0 | |
m[i]+=1 | |
for i,j in m.items(): | |
if j==1: | |
return i |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Class Solution: | |
def romanToInt(self, s: str) -> int: | |
roman = {'M': 1000,'D': 500 ,'C': 100,'L': 50,'X': 10,'V': 5,'I': 1} | |
sum= 0 | |
for i in range(0, len(s) - 1): | |
if roman[s[i]] < roman[s[i+1]]: | |
sum -= roman[s[i]] | |
else: | |
sum+= roman[s[i]] | |
return sum + roman[s[-1]] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution: | |
def isPalindrome(self, x: int) -> bool: | |
s=str(x) | |
for x in range(len(s)//2): | |
if s[x]!=s[-x-1]: | |
return False | |
return True | |