전체 글351 [leetcode 1234]Replace the Substring for Balanced String You are given a string containing only 4 kinds of characters 'Q', 'W', 'E' and 'R'. A string is said to be balanced if each of its characters appears n/4 times where n is the length of the string. Return the minimum length of the substring that can be replaced with any other string of the same length to make the original string s balanced. Return 0 if the string is already balanced. Example 1: I.. 2020. 10. 1. [leetcode 1248] Count Number of Nice Subarrays Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it. Return the number of nice sub-arrays. Example 1: Input: nums = [1,1,2,1,1], k = 3 Output: 2 Explanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1]. Example 2: Input: nums = [2,4,6], k = 1 Output: 0 Explanation: There is no odd numbers in the array. Exa.. 2020. 10. 1. [알고리즘] Prefix Sum 구간 합/누적 합 알고리즘 prefix sum이란 구간 합을 의미한다. 예를 들어, int arr[5] = {10,20,30,40,50}; prefix sum은 prefix[i] = prefix[i-1] + arr[i]일 것이다. int prefix[5]; prefix[0] = arr[0]; for(int i=1; i 2020. 10. 1. [leetcode 986] Interval List Intersections Given two lists of closed intervals, each list of intervals is pairwise disjoint and in sorted order. Return the intersection of these two interval lists. (Formally, a closed interval [a, b] (with a 2020. 9. 30. [leetcode 1004] Max Consecutive Ones III Given an array A of 0s and 1s, we may change up to K values from 0 to 1. Return the length of the longest (contiguous) subarray that contains only 1s. 0과 1로 구성된 배열이 있을 때 K개수 만큼 0을 1로 변경가능하다. 1로 구성된 가장 긴 배열의 길이를 찾아라. Example 1: Input: A = [1,1,1,0,0,0,1,1,1,1,0], K = 2 Output: 6 Explanation: [1,1,1,0,0,1,1,1,1,1,1] Bolded numbers were flipped from 0 to 1. The longest subarray is underlined. Examp.. 2020. 9. 30. 이전 1 ··· 64 65 66 67 68 69 70 71 다음