본문 바로가기

SW/Algorithm Problem (Coding)4

1423. Maximum Points You Can Obtain from Cards(Medium) Maximum Points You Can Obtain from Cards - 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: def maxScore(self, cardPoints: List[int], k: int) -> int: # #Find Min Sum in a row # sum_in_a_row_dict = dict() # key : (start_idx, # of elemnets) value : sum # sum_in_a_row_d.. 2020. 12. 9.
304. Range Sum Query 2D - Immutable(Medium) Range Sum Query 2D - Immutable - 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 이것도 DP문제라면 DP문제. 합을 누적해서 활용해야 하니깐. 가장 큰 사각형에서 row기준, col기준으로 각각 빼주고 중복뺀건 더해주면 된다. class NumMatrix: matrix = list() matrix_sum = dict() def sumArr(self, row, col): sum = 0 for i in range(row+1): sum += .. 2020. 11. 5.
1640. Check Array Formation Through Concatenation(Easy) Check Array Formation Through Concatenation - 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 단순 배열을 잘 돌아다니는 For문 문제다. 2트만에 Accepted가 되었다... easy인데... 처음 제출했을때 문제를 잘못 이해하고 있었다. pieces는 순서를 바꿔서 합칠수 있다! easy 문제는 풀지 말아야되나... class Solution: def canFormArray(self, arr: List[int], piece.. 2020. 11. 5.
1301. Number of Paths with Max Score(Hard) Number of Paths with Max Score - 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 문제 자체는 심플한 DP문제다. 어렸을 적 왕수학(?) 계산법으로 경로의 수를 구하는 방법이 결국엔 DP아니었나 싶다. 4트만에 Accepted가 되었는데... 문제를 풀면서 2개의 삽질이 있었다. 1개의 프로그래밍 언어적 잘못과 1개의 문제를 이해하지 못한 잘못이다. 1. 이중 리스트로 배열을 만드는데, 리스트 객체를 가지는 리스트를 만들어서 참조로 인한 .. 2020. 11. 3.