Algorithm/python tip
-
807. Max Increase to Keep City SkylineAlgorithm/python tip 2021. 3. 2. 11:31
leetcode.com/problems/max-increase-to-keep-city-skyline/ Max Increase to Keep City Skyline - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com class Solution(object): def maxIncreaseKeepingSkyline(self, grid): v_max = [] for i in range(0, len(grid)): v_max.append(max(grid[i])) s_max ..
-
1046. Last Stone WeightAlgorithm/python tip 2021. 3. 2. 11:08
leetcode.com/problems/last-stone-weight/ Last Stone Weight - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com class Solution(object): def lastStoneWeight(self, stones): while len(stones) > 1: stones.sort(reverse=True) stones.append(abs(stones[0] - stones[1])) stones.pop(0) stones.po..
-
[programmers] 스택/큐 - 기능개발Algorithm/python tip 2021. 3. 2. 00:52
programmers.co.kr/learn/courses/30/lessons/42586 코딩테스트 연습 - 기능개발 프로그래머스 팀에서는 기능 개선 작업을 수행 중입니다. 각 기능은 진도가 100%일 때 서비스에 반영할 수 있습니다. 또, 각 기능의 개발속도는 모두 다르기 때문에 뒤에 있는 기능이 앞에 있는 programmers.co.kr def solution(progresses, speeds): working = 0 cnt = 0 ans = [] # 처음 배포해야할 작업이 완료 될때까지 작업 진행 while working < len(progresses): while progresses[working] < 100: for i in range(working, len(progresses)): if prog..
-
1588. Sum of All Odd Length SubarraysAlgorithm/python tip 2021. 3. 1. 20:13
leetcode.com/problems/sum-of-all-odd-length-subarrays/ Sum of All Odd Length Subarrays - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com # 가능한 홀수 갯수 sublist class Solution(object): def sumOddLengthSubarrays(self, arr): ans = 0 for i in range(1, len(arr) + 1, 2): for j in range(0, l..
-
1732. Find the Highest AltitudeAlgorithm/python tip 2021. 3. 1. 19:58
leetcode.com/problems/find-the-highest-altitude/ Find the Highest Altitude - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com class Solution(object): def largestAltitude(self, gain): result = [0] for i in range(0, len(gain)): result.append(result[i] + gain[i]) return max(result) """..
-
1679. Max Number of K-Sum PairsAlgorithm/python tip 2021. 3. 1. 18:13
leetcode.com/problems/max-number-of-k-sum-pairs/ Max Number of K-Sum Pairs - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com from collections import Counter class Solution(object): def maxOperations(self, nums, k): dic = Counter(nums) ans = 0 for n in nums: if k - n in dic: if n ==..
-
137. Single Number IIAlgorithm/python tip 2021. 3. 1. 17:56
leetcode.com/problems/single-number-ii/ Single Number II - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com class Solution(object): def singleNumber(self, nums): dic = {k: 0 for k in nums} for k in nums: dic[k] += 1 print(dic) for k, v in dic.items(): if v == 1: return k