![[Leetcode] 643 Maximum Average Subarray I (Python)](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdna%2FbPwj9U%2FbtsQrTjluoS%2FAAAAAAAAAAAAAAAAAAAAADOtd45H6vMnV9HZyLJBTf1GFuKUBcHHXRvLZ9tSQZ63%2Fimg.png%3Fcredential%3DyqXZFxpELC7KVnFOS48ylbz2pIh7yKj8%26expires%3D1759244399%26allow_ip%3D%26allow_referer%3D%26signature%3D8z7UV1gVdgD8cqykYwVv27bZWAM%253D)
문제Maximum Average Subarray I - LeetCode설명You are given an integer array nums consisting of n elements, and an integer k. Find a contiguous subarray whose length is equal to k that has the maximum average value and return this value. Any answer with a calculation error less than 10-5 will be accepted.풀이 계획배열을 n-k만큼 돌면서 모든 경우의 최대합 값을 비교하여 구한다. 마지막까지 돌고 반복문을 나와서 최대합 값을 k로 나눈 값을 리턴하면 될 것으로 생각했다. 배열의..
![[Leetcode] 283 Move Zeros (Python)](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdna%2Fcx4DCG%2FbtsQqHbwQnQ%2FAAAAAAAAAAAAAAAAAAAAACfbD917ejfrgGTDLfLprUTF7F616CypX7oN0FdWtXXQ%2Fimg.png%3Fcredential%3DyqXZFxpELC7KVnFOS48ylbz2pIh7yKj8%26expires%3D1759244399%26allow_ip%3D%26allow_referer%3D%26signature%3Dp4Bn18%252BtM9aoq0d5N%252Bcf%252FULkb7g%253D)
문제https://leetcode.com/problems/move-zeroes 설명Given an integer array nums, move all 0's to the end of it while maintaining the relative order of the non-zero elements.Note that you must do this in-place without making a copy of the array.풀이 계획원본 배열을 수정하는 방식으로 풀어야 한다는 것이 포인트인 것 같다. nums 리스트를 돌면서 i번째 리스트에 0이 있다면 해당 인덱스부터 n-1번째 요소 까지 우측과 바꿔가면서 0이 점점 우측으로 몰리게끔 풀어보았다.초기 풀이class Solution: def moveZ..
![[Leetcode] 2348 Number of Zero-Filled Subarrays (Python)](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdna%2F0MNZd%2FbtsPY9MAf6C%2FAAAAAAAAAAAAAAAAAAAAAAWM_s7Z4xOsaWlueMrS16dGK5t24ArBQWS5x6Y-PcHD%2Fimg.png%3Fcredential%3DyqXZFxpELC7KVnFOS48ylbz2pIh7yKj8%26expires%3D1759244399%26allow_ip%3D%26allow_referer%3D%26signature%3Dm1owVXf%252B0JFpl4GRzG1DoVzxYBg%253D)
Number of Zero-Filled Subarrays - LeetCode생각리스트를 한번 돌면서 0이 이어진다면 몇번까지 이어지는지 확인하고 이어지는 그룹이 몇개인지도 파악한다.몇번까지 이어지는지만 알면 subarrays 개수는 구할 수 있다.그때그때 0이 이어지는 상태인지 확인이 필요하다.삼각수 배열을 미리 뽑아놓고 갖다 쓰면 좋지 않을까?초기코드class Solution: def zeroFilledSubarray(self, nums: List[int]) -> int: limit = 10**5 triangular_numbers = [n * (n + 1) // 2 for n in range(1, limit + 1)] arr = [] streakF..