LeetCode84 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. Sum Root to Leaf Numbers Problem: Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number. An example is the root-to-leaf path 1->2->3 which represents the number 123. Find the total sum of all root-to-leaf numbers. Note: A leaf is a node with no children. -Summary- Used recursive DFS. # Definition for a binary tree node. # class TreeNode: # def __init__(self, val=0, left=Non.. 2020. 6. 27. LeetCode. Min Stack Problem: Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. push(x) -- Push element x onto stack. pop() -- Removes the element on top of the stack. top() -- Get the top element. getMin() -- Retrieve the minimum element in the stack. Example 1: -Summary- Use tuple to save the minimum value and the current value of the stack. class MinStack: def __ini.. 2020. 6. 26. LeetCode. Shuffle an Array Problem: Shuffle a set of numbers without duplicates. Example: // Init an array with set 1, 2, and 3. int[] nums = {1,2,3}; Solution solution = new Solution(nums); // Shuffle the array [1,2,3] and return its result. Any permutation of [1,2,3] must equally likely to be returned. solution.shuffle(); // Resets the array back to its original configuration [1,2,3]. solution.reset(); // Returns the ra.. 2020. 6. 24. 이전 1 2 3 4 5 ··· 14 다음