본문 바로가기

반응형

LeetCode

(6)
LeetCode 1021. Remove Outermost Parentheses A valid parentheses string is either empty "", "(" + A + ")", or A + B, where A and B are valid parentheses strings, and + represents string concatenation. For example, "", "()", "(())()", and "(()(()))" are all valid parentheses strings. A valid parentheses string s is primitive if it is nonempty, and there does not exist a way to split it into s = A + B, with A and B nonempty valid parentheses..
Leetcode 1018. Binary Prefix Divisible By 5 You are given a binary array nums (0-indexed). We define xi as the number whose binary representation is the subarray nums[0..i] (from most-significant-bit to least-significant-bit). For example, if nums = [1,0,1], then x0 = 1, x1 = 2, and x2 = 5. Return an array of booleans answer where answer[i] is true if xi is divisible by 5. Constraints: 1 1 / 5는 정확히 나눠지지 않으므로 false. 011 -> 3 / 5도 정확히 나눠지지 ..
Leetcode 1013. Partition Array Into Three Parts With Equal Sum Given an array of integers arr, return true if we can partition the array into three non-empty parts with equal sums. Formally, we can partition the array if we can find indexes i + 1 < j with (arr[0] + arr[1] + ... + arr[i] == arr[i + 1] + arr[i + 2] + ... + arr[j - 1] == arr[j] + arr[j + 1] + ... + arr[arr.length - 1]) 정수 배열 arr이 주어졌을 때 비지 않는 3개의 배열 나눈 부분들의 합이 같을 시 참을 반환하라. 공식적으로 인덱스 i + 1 < j..
Leetcode 1009. Complement of Base 10 Integer The complement of an integer is the integer you get when you flip all the 0's to 1's and all the 1's to 0's in its binary representation. For example, The integer 5 is "101" in binary and its complement is "010" which is the integer 2. Given an integer n, return its complement 한 정수의 2진수 표기법에서 모든 비트 0을 1로 바꾸고 1을 0으로 바꿨을 때 그 결괏값이 정수의 보수이다. 예를 들어, 정수 5의 2진수는 101이고 101의 보수는 010이고 010은 정수 2이다. 정수 n가 ..
Leetcode 1005. Maximize Sum Of Array After K Negations Given an integer array nums and an integer k, modify the array in the following way: choose an index i and replace nums[i] with -nums[i]. You should apply this process exactly k times. You may choose the same index i multiple times. Return the largest possible sum of the array after modifying it in this way. 주어진 정수 배열과 정수 k를 가지고 다음과 같은 방법으로 배열을 수정해라: 인자 i를 고르고 num[i]의 값을 -num[i]으로 바꿔라. 이 방법을 정확히..
Leetcode 1002. Find Common Characters Given a string array words, return an array of all characters that show up in all strings within the words (including duplicates). You may return the answer in any order. 문자열 배열을 주어졌을 때, 모든 문자열에 공통으로 들어있는 문자들을 구하시오. 리턴 값의 순서는 상관없음. Example 1: Input: words = ["bella","label","roller"] Output: ["e","l","l"] Example 2: Input: words = ["cool","lock","cook"] Output: ["c","o"] a부터 z를 카운트할 정수 배열로 풀려했지만..