본문 바로가기

array5

Leetcode. Find Numbers with Even Number of Digits Problem: Given an array nums of integers, return how many of them contain an even number of digits. -Summary- 1. Format change int to string for each number and count the length of the str format of the number. 2. Check if it is even or odd number of digits. class Solution: def findNumbers(self, nums: List[int]) -> int: count = 0 for num in nums: if len(str(num)) % 2 == 0: count += 1 return coun.. 2020. 7. 1.
LeetCode. Unique Paths Problem: A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid (marked 'Finish' in the diagram below). How many possible unique paths are there? Above is a 7 x 3 grid. How many possible unique paths are there? Example: -Cod.. 2020. 6. 30.
Leetcode. Max Consecutive Ones Problem: Given a binary array, find the maximum number of consecutive 1s in this array. Example 1: Input: [1,1,0,1,1,1] Output: 3 Explanation: The first two digits or the last three digits are consecutive 1s. The maximum number of consecutive 1s is 3. Note: The input array will only contain 0 and 1. The length of input array is a positive integer and will not exceed 10,000 class Solution: def fi.. 2020. 6. 29.
LeetCode 41. First Missing Positive Problem: Given an unsorted integer array, find the smallest missing positive integer. Example 1: Input: [1,2,0] Output: 3 Example 2: Input: [3,4,-1,1] Output: 2 Example 3: Input: [7,8,9,11,12] Output: 1 -Summary- 1. Set first positive integer as 1 --> posNum 2. loop-through the nums and check if posNum is in the nums list. (max int: 2^31 -1) - if there is, adding 1 more value to posNum and find .. 2020. 6. 18.
LeetCode 238. Product of Array Except Self [Array] Problem: Given an array nums of n integers where n > 1, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i]. Example: Input: [1,2,3,4] Output: [24,12,8,6] Constraint: It's guaranteed that the product of the elements of any prefix or suffix of the array (including the whole array) fits in a 32 bit integer. Note: Please solve it without div.. 2020. 6. 16.