목록leet code (85)
N
https://leetcode.com/problems/number-of-zero-filled-subarrays/ Number of Zero-Filled Subarrays - LeetCode Can you solve this real interview question? Number of Zero-Filled Subarrays - Given an integer array nums, return the number of subarrays filled with 0. A subarray is a contiguous non-empty sequence of elements within an array. Example 1: Input: nums = leetcode.com const zeroFilledSubarray =..
https://leetcode.com/problems/capacity-to-ship-packages-within-d-days/description/ Capacity To Ship Packages Within D Days - LeetCode Can you solve this real interview question? Capacity To Ship Packages Within D Days - A conveyor belt has packages that must be shipped from one port to another within days days. The ith package on the conveyor belt has a weight of weights[i]. Each day, we leetcod..
https://leetcode.com/problems/wiggle-subsequence/ Wiggle Subsequence - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 주어진 배열에서 조건에 맞는 길이의 최대값을 찾아야 한다. 인접한 수의 차가 + - + - ... or - + - +... 면 된다. answer = 1부터 시작하는데, 이는 0번째 값은 무조건 답이 될 수 있는 최소값이 되기 때문이다. flag를 이용해 현재 값 차이가 양수인지, 음수인지 ..
https://leetcode.com/problems/non-decreasing-array/ Non-decreasing Array - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 주어진 nums 배열을 최대 1개의 원소만 바꿔서 오름차순 정렬이 가능한지 확인하는 문제. 변경 여부를 확인할 수 있는 flag인 isModified = false로 선언한다. for문으로 nums를 순회하는데, 인덱스는 1부터 시작한다. 만약 현재 방문한 원소가 이전 원소보다 값이 ..
https://leetcode.com/problems/repeated-substring-pattern/ Repeated Substring Pattern - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 문자열 패턴 찾기 문제. 이중 for문으로 쉽게 해결할 수 있다. 먼저 pattern을 0번째 인덱스부터 i번째 인덱스까지 자른다. 그리고 isRepeated라는 flag를 설정하고, 내부 for문이 모두 돌게 되면 isRepated는 바뀌지 않아 패턴 문자열이라..
https://leetcode.com/problems/find-all-numbers-disappeared-in-an-array/ Find All Numbers Disappeared in an Array - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com nums 배열에서 없는 수를 answer에 담아 리턴하면 된다. 1 부터 nums.length 까지의 수가 nums에 담겨있다. check라는 배열을 length + 1 크기로 선언하고 false로 초기화한다. n..
https://leetcode.com/problems/third-maximum-number/ Third Maximum Number - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com map을 활용. nums에는 중복된 수가 있을 수 있기 때문에, 중복을 제거하기 위해 map을 선언한다. 그리고 nums를 순회하면서 map에 nums[i]에 해당하는 수가 없으면 nums[i]를 key로 하여 value를 true로 해준다. 순회가 끝나면 다음은 map을 순회한다. ..
https://leetcode.com/problems/longest-consecutive-sequence/ Longest Consecutive Sequence - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com Union-Find와 Map을 활용 parent라는 map을 선언. nums[i]를 순회하면서 key와 value를 모두 자기 자신인 nums[i]로 초기화한다. 이후 연속된 수의 부모를 하나로 합치는 작업을 진행. nums[i]를 순회하면서 unionPa..