LeetCode/Arrays 1013 Leetcode. Squares of a Sorted Array Problem: Given an array of integers A sorted in non-decreasing order, return an array of the squares of each number, also in sorted non-decreasing order. Example 1: Input: [-4,-1,0,3,10] Output: [0,1,9,16,100] Example 2: Input: [-7,-3,2,3,11] Output: [4,9,9,49,121] -Summary- Squares of each element in Array, then sort them using sort() function. class Solution: def sortedSquares(self, A: List[in.. 2020. 7. 4. 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. 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. 이전 1 다음