본문 바로가기

python-algorithm1422

Leetcode 50. Pow(x, n) 1 2 3 class Solution: def myPow(self, x: float, n: int) -> float: return pow(x,n) cs 2021. 7. 15.
Leetcode 43. Multiply Strings 1 2 3 class Solution: def multiply(self, num1: str, num2: str) -> str: return str (int(num1)*int(num2)) cs 딱히 어려운 문제는 아니구 Type casting만 신경쓰시면됩니다 2021. 7. 15.
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.
백준 22193 Multiply 1 2 3 4 a,b=map( int, input().split()) c1=int(input()) c2=int(input()) print(c1*c2) cs 2021. 7. 15.
백준 5539 콜센터 1 2 3 4 5 6 7 8 9 10 print(" /~\\") print(" ( oo|") print(" _\=/_") print(" / _ \\") print(" //|/.\|\\\\") print(" || \ / ||") print("============") print("| |") print("| |") print("| |") 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.