본문 바로가기

LeetCode340

Leetcode 29. Divide Two Integers 1 2 3 4 5 6 7 8 class Solution: def divide(self, dividend: int, divisor: int) -> int: ans=int(dividend/divisor) if ans>pow(2,31)-1 : ans=pow(2,31)-1 if ans 2021. 7. 15.
Leetcode 66. Plus One 1 2 3 4 5 6 7 8 9 10 11 class Solution: def plusOne(self, digits: List[int]) -> List[int]: s="" for i in digits: s+=str(i) s=int(s)+1 s=str(s) tmp=[] for i in s: tmp.append(int(i)) return tmp cs 2021. 7. 15.
Leetcode 67. Add Binary 1 2 3 4 5 class Solution: def addBinary(self, a: str, b: str) -> str: ans= int(a,2)+int(b,2) ans= bin(ans)[2:] return ans cs 2021. 7. 15.
Leetcode 69. Sqrt(x) 1 2 3 4 import math class Solution: def mySqrt(self, x: int) -> int: return int (math.sqrt(x)) cs 2021. 7. 15.
Leetcode 28. Implement strStr() 1 2 3 4 class Solution: def strStr(self, haystack: str, needle: str) -> int: if needle in haystack : return (haystack.index(needle)) else: return -1 Colored by Color Scripter cs 2021. 7. 13.
Leetcode 1512. Number of Good Pairs 1 2 3 4 5 6 7 8 class Solution: def numIdenticalPairs(self, nums: List[int]) -> int: ans=0 for i in range(len(nums)): for j in range(i,len(nums)): if nums[i]==nums[j]: if i 2021. 7. 13.
Leetcode 1470. Shuffle the Array 1 2 3 4 5 6 7 class Solution: def shuffle(self, nums: List[int], n: int) -> List[int]: tmp=[] for i in range(n): tmp.append(nums[i]) tmp.append(nums[n+i]) return tmp Colored by Color Scripter cs 2021. 7. 13.
Leetcode 1431. Kids With the Greatest Number of Candies 1 2 3 4 5 6 7 8 9 class Solution: def kidsWithCandies(self, candies: List[int], extraCandies: int) -> List[bool]: listMax=max(candies) ans=[] for i in candies: if i+extraCandies>=listMax : ans.append(True) else: ans.append(False) return ans Colored by Color Scripter cs 2021. 7. 13.
Leetcode 9. Palindrome Number 1 2 3 4 5 class Solution: def isPalindrome(self, x: int) -> bool: x=str(x) if x== x[::-1] : return True else : return False cs 팰린드롬 숫자 백준에도 많이 있는 유형이에요 쉽습니다 2021. 7. 12.
Leetcode 7. Reverse Integer 1 2 3 4 5 6 7 8 9 10 class Solution: def reverse(self, x: int) -> int: x=str(x) if x[0]=='-': x=int(x[::-1][:-1])*-1 if x=pow(2,31)-1 : x=0 return x cs 문제 자체는 안어려운데요 예외조건 Given~ 부분 잘 읽어보셔야됩니더 2021. 7. 12.
Leetcode 1. Two Sum 1 2 3 4 5 6 7 8 9 10 class Solution: 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]: tmp=[] tmp.append(i) tmp.append(j) return tmp break Colored by Color Scripter cs 2021. 7. 12.
Leetcode 1672. Richest Customer Wealth 1 2 3 4 5 6 7 class Solution: def maximumWealth(self, accounts: List[List[int]]) -> int: tmp=[] for i in range(len(accounts)): tmp.append( sum(accounts[i])) return max(tmp) Colored by Color Scripter cs 2021. 7. 12.