코딩92 LeetCode. Count Primes [Math] Problem: Count the number of prime numbers less than a non-negative number, n. Example: Input: 10 Output: 4 Explanation: There are 4 prime numbers less than 10, they are 2, 3, 5, 7. -Summary- Used Sieve of Eratosthenes 1. List all the numbers start from the 2. 2. 2 is a Prime number. 3. Remove all the number that is multiple of 2. 4. The smallest number that is not removed, is a 3 which is a pri.. 2020. 6. 14. LeetCode. Largest Divisible Subset Problem: Given a set of distinct positive integers, find the largest subset such that every pair (Si, Sj) of elements in this subset satisfies: Si % Sj = 0 or Sj % Si = 0. If there are multiple solutions, return any subset is fine. Example 1: Input: [1,2,3] Output: [1,2] (of course, [1,3] will also be ok) Example 2: Input: [1,2,4,8] Output: [1,2,4,8] -Summary- 1. Sort the input nums list (*Sorti.. 2020. 6. 14. LeetCode 34. Find First and Last Position of Element in Sorted Array [Binary Search] Problem: Given an array of integers nums sorted in ascending order, find the starting and ending position of a given target value. Your algorithm's runtime complexity must be in the order of O(log n). If the target is not found in the array, return [-1, -1]. Example 1: Input: nums = [5,7,7,8,8,10], target = 8 Output: [3,4] Example 2: Input: nums = [5,7,7,8,8,10], target = 6 Output: [-1,-1] -Summ.. 2020. 6. 13. LeetCode. Fizz Buzz [Math] Problem: Write a program that outputs the string representation of numbers from 1 to n. But for multiples of three it should output “Fizz” instead of the number and for the multiples of five output “Buzz”. For numbers which are multiples of both three and five output “FizzBuzz”. Example: n = 15, Return: [ "1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz", "11", "Fizz", "13", "14", .. 2020. 6. 13. LeetCode. Sort Colors Problems: Given an array with n objects colored red, white or blue, sort them in-place so that objects of the same color are adjacent, with the colors in the order red, white and blue. Here, we will use the integers 0, 1, and 2 to represent the color red, white, and blue respectively. Note: You are not suppose to use the library's sort function for this problem. Example: Input: [2,0,2,1,1,0] Out.. 2020. 6. 12. LeetCode 5. Valid Parentheses [Strings, Stack] Problem: Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. An input string is valid if: Open brackets must be closed by the same type of brackets. Open brackets must be closed in the correct order. Note that an empty string is also considered valid. Example 1: Input: "()" Output: true Example 2: Input: "()[]{}" Output: true Exa.. 2020. 6. 12. 이전 1 2 3 4 5 6 ··· 16 다음