목록Leetcode (26)
mjk study log
문제You are given a 0-indexed integer array nums.Return the maximum value over all triplets of indices (i, j, k) such that i The value of a triplet of indices (i, j, k) is equal to (nums[i] - nums[j]) * nums[k]. Example 1:Input: nums = [12,6,1,2,7] Output: 77 Explanation: The value of the triplet (0, 2, 4) is (nums[0] - nums[2]) * nums[4] = 77. It can be shown that there are no ordered triplets of..
문제You are given a 0-indexed integer array nums.Return the maximum value over all triplets of indices (i, j, k) such that i The value of a triplet of indices (i, j, k) is equal to (nums[i] - nums[j]) * nums[k]. Example 1:Input: nums = [12,6,1,2,7] Output: 77 Explanation: The value of the triplet (0, 2, 4) is (nums[0] - nums[2]) * nums[4] = 77. It can be shown that there are no ordered triplets of..
문제You are given a string s.A split is called good if you can split s into two non-empty strings sleft and sright where their concatenation is equal to s (i.e., sleft + sright = s) and the number of distinct letters in sleft and sright is the same.Return the number of good splits you can make in s. Example 1:Input: s = "aacaba" Output: 2 Explanation: There are 5 ways to split "aacaba" and 2 of th..
문제There are 8 prison cells in a row and each cell is either occupied or vacant.Each day, whether the cell is occupied or vacant changes according to the following rules:If a cell has two adjacent neighbors that are both occupied or both vacant, then the cell becomes occupied.Otherwise, it becomes vacant.Note that because the prison is a row, the first and the last cells in the row can't have two..
문제Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target.You may assume that each input would have exactly one solution, and you may not use the same element twice.You can return the answer in any order. Example 1:Input: nums = [2,7,11,15], target = 9 Output: [0,1] Explanation: Because nums[0] + nums[1] == 9, we return [0, 1]. Exa..
문제You are given a string s and an integer k. You can choose any character of the string and change it to any other uppercase English character. You can perform this operation at most k times.Return the length of the longest substring containing the same letter you can get after performing the above operations. Example 1:Input: s = "ABAB", k = 2 Output: 4 Explanation: Replace the two 'A's with tw..
문제You are given two strings s and t of the same length and an integer maxCost.You want to change s to t. Changing the ith character of s to ith character of t costs |s[i] - t[i]| (i.e., the absolute difference between the ASCII values of the characters).Return the maximum length of a substring of s that can be changed to be the same as the corresponding substring of t with a cost less than or eq..
문제Given a sorted integer array arr, two integers k and x, return the k closest integers to x in the array. The result should also be sorted in ascending order.An integer a is closer to x than an integer b if:|a - x| Example 1:Input: arr = [1,2,3,4,5], k = 4, x = 3Output: [1,2,3,4]Example 2:Input: arr = [1,1,2,3,4,5], k = 4, x = -1Output: [1,1,2,3] Constraints:1 풀이1처음 이 문제를 봤을 때, 각 element의 거리를..
문제Given the root of a binary tree, return the maximum width of the given tree.The maximum width of a tree is the maximum width among all levels.The width of one level is defined as the length between the end-nodes (the leftmost and rightmost non-null nodes), where the null nodes between the end-nodes that would be present in a complete binary tree extending down to that level are also counted in..
문제Given a binary array nums, return the maximum length of a contiguous subarray with an equal number of 0 and 1.Example 1:Input: nums = [0,1]Output: 2Explanation: [0, 1] is the longest contiguous subarray with an equal number of 0 and 1.Example 2:Input: nums = [0,1,0]Output: 2Explanation: [0, 1] (or [1, 0]) is a longest contiguous subarray with equal number of 0 and 1.Constraints:1 nums[i] is ei..