릿코드

    [LeetCode] Find All Numbers Disappeared in an Array

    [LeetCode] Find All Numbers Disappeared in an Array

    🔍 문제 Given an array nums of n integers where nums[i] is in the range [1, n], return an array of all the integers in the range [1, n] that do not appear in nums. Input: nums = [4,3,2,7,8,2,3,1] Output: [5,6] Input: nums = [1,1] Output: [2] Tip) The intuition behind using a hash map is pretty clear in this case 🖥 실행 1) Answer(Hash Table) class Solution(object): def findDisappearedNumbers(self, num..

    [LeetCode] Max Consecutive Ones II

    [LeetCode] Max Consecutive Ones II

    🔍 문제 Given a binary array nums, return the maximum number of consecutive 1's in the array if you can flip at most one 0. nput: nums = [1,0,1,1,0] Output: 4 Explanation: Flip the first zero will get the maximum number of consecutive 1s. After flipping, the maximum number of consecutive 1s is 4. 🖥 실행 1) Answer class Solution(object): def findMaxConsecutiveOnes(self, nums): # previous and current l..

    [LeetCode] Height Checker

    [LeetCode] Height Checker

    🔍 문제 A school is trying to take an annual photo of all the students. The students are asked to stand in a single file line in non-decreasing order by height. Let this ordering be represented by the integer array expected where expected[i] is the expected height of the ith student in line. You are given an integer array heights representing the current order that the students are standing in. Eac..

    [LeetCode] Move Zeroes

    [LeetCode] Move Zeroes

    🔍 문제 Given an integer array nums, move all 0's to the end of it while maintaining the relative order of the non-zero elements. Note that you must do this in-place without making a copy of the array. Input: nums = [0,1,0,3,12] Output: [1,3,12,0,0] Input: nums = [0] Output: [0] 🖥 실행 1) Answer class Solution: def moveZeroes(self, nums: List[int]) -> None: n = 0 while nums.count(0) > n: nums.remove(..

    [LeetCode] Valid Mountain Array

    [LeetCode] Valid Mountain Array

    🔍 문제 Given an array of integers arr, return true if and only if it is a valid mountain array. Recall that arr is a mountain array if and only if: arr.length >= 3 There exists some i with 0 ... > arr[arr.length - 1] Input: arr = [2,1] Output: false Input: arr = [3,5,5] Output: false Input: arr = [0,3,2,1] Output: true 🖥 실행 ..

    [LeetCode] Find Numbers with Even Number of Digits

    [LeetCode] Find Numbers with Even Number of Digits

    🔍 문제 Given an array nums of integers, return how many of them contain an even number of digits. nums = [12,345,2,6,7896] Output: 2 Explanation: 12 contains 2 digits (even number of digits). 345 contains 3 digits (odd number of digits). 2 contains 1 digit (odd number of digits). 6 contains 1 digit (odd number of digits). 7896 contains 4 digits (even number of digits). Therefore only 12 and 7896 c..