본문 바로가기

python-algorithm1422

백준 24079 移動 (Moving) 1 2 3 4 5 x=int(input()) y=int(input()) z=int(input()) if x+y>z : print(0) else : print(1) cs 2022. 4. 12.
백준 알고리즘 수업 - 알고리즘의 수행 시간 1 1 2 print(1) print(0) cs 이 로직은 입력값에 따라 변하는게 없네요 2022. 4. 12.
leetcode 2235. Add Two Integers 1 2 3 class Solution: def sum(self, num1: int, num2: int) -> int: return num1+num2 cs 2022. 4. 12.
leetcode 682. Baseball Game 1 2 3 4 5 6 7 8 9 10 class Solution: def calPoints(self, ops: List[str]) -> int: record=[] for i in ops : if i.isnumeric() : record.append(int(i)) if i[0]=='-' : record.append(int(i[1:])*-1) if i == 'C': record.pop() if i == 'D': record.append(record[-1]*2) if i == '+': record.append(record[-1]+record[-2]) return (sum(record)) Colored by Color Scripter cs 2022. 4. 11.
leetcode 1507. Reformat Date 1 2 3 4 5 6 class Solution: def reformatDate(self, date: str) -> str: month=["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"] date=date.split() ans=date[2]+'-'+'%.2d'%(month.index(date[1])+1)+'-'+'%.2d'%(int(date[0][:-2])) return(ans) Colored by Color Scripter cs 2022. 4. 8.
leetcode 169. Majority Element 1 2 3 4 5 class Solution: def majorityElement(self, nums: List[int]) -> int: nums_set=list(set(nums)) for i in nums_set: if nums.count(i)>=len(nums)/2 : return(i); break cs 2022. 4. 8.
leetcode 258. Add Digits 1 2 3 4 5 6 7 8 class Solution: def addDigits(self, num: int) -> int: while num>=10: tmp = 0 for i in (str(num)): tmp+=int(i) num=tmp return (num) cs 2022. 4. 8.
leetcode 1550. Three Consecutive Odds 1 2 3 4 5 6 7 8 class Solution: def threeConsecutiveOdds(self, arr: List[int]) -> bool: ans=False for i in range(2,len(arr)): if arr[i]%2 == 1 and arr[i-1]%2 == 1 and arr[i-2]%2 == 1 : ans = True break return ans Colored by Color Scripter cs 2022. 4. 4.
leetcode 1800. Maximum Ascending Subarray Sum 1 2 3 4 5 6 7 8 9 10 11 12 13 14 class Solution: def maxAscendingSum(self, nums: List[int]) -> int: ans=[] tmp=0 if len(nums)== 1: ans.append(nums[0]) else : for i in range(len(nums)-1): if nums[i] 2022. 4. 4.
leetcode 896. Monotonic Array 1 2 3 4 5 6 class Solution: def isMonotonic(self, nums: List[int]) -> bool: ans=False if nums == sorted(nums) or nums==sorted(nums,reverse=True) : ans=True return ans Colored by Color Scripter cs 2022. 3. 28.
leetcode 1185. Day of the Week 1 2 3 4 from datetime import datetime class Solution: def dayOfTheWeek(self, day: int, month: int, year: int) -> str: return datetime(year,month,day).strftime('%A') cs 2022. 3. 28.
leetcode 448. Find All Numbers Disappeared in an Array 1 2 3 4 class Solution: def findDisappearedNumbers(self, nums: List[int]) -> List[int]: n=len(nums) return set(range(1,n+1))-set(nums) cs 2022. 3. 28.