python-algorithm1422 leetcode 128. Longest Consecutive Sequence 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 class Solution: def longestConsecutive(self, nums: List[int]) -> int: nums=list(set(nums)) nums.sort() ans=1 start=1 for i in range(1,len(nums)): if nums[i]-1 == nums[i-1] : start+=1 else : ans=max(ans,start) start=1 ans=max(ans,start) if len(nums) ==0 : ans=0 return ans Colored by Color Scripter cs 2022. 7. 6. leetcode 509. Fibonacci Number 1 2 3 4 5 class Solution: def fib(self, n: int) -> int: if n==0 : return 0 elif n== 1: return 1 else : return self.fib(n-1)+self.fib(n-2) cs memoization 이나 DP 방식으로도 풀 수있는데 recursion으로 풀어도 time limit 안걸리고 되네용 2022. 7. 6. leetcode 462. Minimum Moves to Equal Array Elements II 1 2 3 4 5 6 7 8 from statistics import median class Solution: def minMoves2(self, nums: List[int]) -> int: med=median(nums) ans=0 for i in nums : ans+=abs(med-i) return int(ans) cs 2022. 6. 30. 백준 2756 다트 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 pydef cal_score(x,y): score=0 distance=x**2+y**2 if distance 2022. 6. 17. 백준 14647 준오는 조류혐오야!! 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 def cnt_max_matrix(nums): row_max=0 row=0 for i in range(len(nums)): tmp_max=0 for j in nums[i]: tmp_max+=j.count('9') if row_max 2022. 6. 16. codeforces 509A - Maximum in Table 1 2 3 4 5 6 7 8 9 10 11 12 13 def sol(n): nums = [[0] * 10]*10 for i in range(n-1): nums.append([1,0,0,0,0]) for i in range(n): for j in range(n): if i == 0 or j == 0 : nums[i][j]=1 else : nums[i][j]=nums[i-1][j]+nums[i][j-1] print(nums[n-1][n-1]) n=int(input()) sol(n) Colored by Color Scripter cs 2022. 6. 13. 백준 23809 골뱅이 찍기 - 돌아간 ㅈ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 def p_first(n): for i in range(n): print('@'*n+' '*3*n+'@'*n) def p_second(n): for i in range(n): print('@' * n + ' ' * 2 * n + '@' * n) def p_mid(n): for i in range(n): print('@' * 3*n) def sol(n): p_first(n) p_second(n) p_mid(n) p_second(n) p_first(n) sol(int(input())) cs 2022. 6. 10. 백준 24265 알고리즘 수업 - 알고리즘의 수행 시간 4 1 2 3 n=int(input()) print((n-1)*(n)//2) print(2) cs 2022. 6. 9. codeforces 1351A - A+B (Trial Problem) 1 2 3 4 5 import sys for i in range(int(input())): a,b=map(int,sys.stdin.readline().split()) print(a+b) Colored by Color Scripter cs 2022. 6. 7. codeforces 677A - Vanya and Fence 1 2 3 4 5 6 7 8 9 10 11 def sol(nums,h): ans = 0 for i in nums: if i > h: ans += 2 else: ans += 1 print(ans) n,h=map(int,input().split()) nums=list(map(int, input().split())) sol(nums,h) cs 2022. 5. 31. codeforces 96A - Football 1 2 3 4 5 6 7 8 def sol(s): target1='0000000' target2 = '1111111' if target1 in s or target2 in s: print("YES") else : print("NO") sol(input()) cs 2022. 5. 31. codeforces 617A - Elephant 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 def sol(n): ans=0 while n>0: if n>=5: n-=5 elif n>=4: n-=4 elif n>=3: n-=3 elif n>=2: n-=2 elif n>=1: n-=1 ans+=1 return ans print(sol(int(input()))) cs 2022. 5. 31. 이전 1 ··· 40 41 42 43 44 45 46 ··· 119 다음