매일 LeetCode 풀기 | Maximum Product Subarray
Given an integer array nums, find a subarray that has the largest product, and return the product.The test cases are generated so that the answer will fit in a 32-bit integer. Example 1:Input: nums = [2,3,-2,4] Output: 6 Explanation: [2,3] has the largest product 6. Example 2:Input: nums = [-2,0,-1] Output: 0 Explanation: The result cannot be 2, because [-2,-1] is not a subarray. Constraints:1 ..
매일 LeetCode 풀기 | Maximum Subarray
Given an integer array nums, find the subarray with the largest sum, and return its sum. Example 1:Input: nums = [-2,1,-3,4,-1,2,1,-5,4] Output: 6 Explanation: The subarray [4,-1,2,1] has the largest sum 6. Example 2:Input: nums = [1] Output: 1 Explanation: The subarray [1] has the largest sum 1. Example 3:Input: nums = [5,4,-1,7,8] Output: 23 Explanation: The subarray [5,4,-1,7,8] has the large..
매일 LeetCode 풀기 | 3Sums
Given an integer array nums, return all the triplets [nums[i], nums[j], nums[k]] such that i != j, i != k, and j != k, and nums[i] + nums[j] + nums[k] == 0.Notice that the solution set must not contain duplicate triplets. Example 1:Input: nums = [-1,0,1,2,-1,-4] Output: [[-1,-1,2],[-1,0,1]] Explanation: nums[0] + nums[1] + nums[2] = (-1) + 0 + 1 = 0. nums[1] + nums[2] + nums[4] = 0 + 1 + (-1) = ..
매일 LeetCode 풀기 | Contains Duplicate
Contains DuplicateGiven an integer array nums, return true if any value appears at least twice in the array, and return false if every element is distinct. Example 1:Input: nums = [1,2,3,1] Output: true Example 2:Input: nums = [1,2,3,4] Output: false Example 3:Input: nums = [1,1,1,3,3,4,3,2,4,2] Output: true Constraints:1 class Solution { func containsDuplicate(_ nums: [Int]) -> Bool { ..