본문 바로가기

LeetCode/Top Interview Q. - Easy47

LeetCode.Number of 1 Bits [Bit] Problem: Write a function that takes an unsigned integer and return the number of '1' bits it has (also known as the Hamming weight). Example 1: Input: 00000000000000000000000000001011 Output: 3 Explanation: The input binary string 00000000000000000000000000001011 has a total of three '1' bits. Example 2: Input: 00000000000000000000000010000000 Output: 1 Explanation: The input binary string 0000.. 2020. 6. 17.
LeetCode.Roman to Integer [Math] Problem: Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M. Symbol Value I 1 V 5 X 10 L 50 C 100 D 500 M 1000 For example, two is written as II in Roman numeral, just two one's added together. Twelve is written as, XII, which is simply X + II. The number twenty seven is written as XXVII, which is XX + V + II. Roman numerals are usually written largest to smallest .. 2020. 6. 16.
LeetCode. Count Primes [Math] Problem: Given an integer, write a function to determine if it is a power of three. Example 1: Input: 27 Output: true Example 2: Input: 0 Output: false Example 3: Input: 9 Output: true Example 4: Input: 45 Output: false Follow up: Could you do it without using any loop / recursion? -Summary- 1. Check if n is bigger than 0 for when input is 0 2. Check if given n can divide the maximum number for .. 2020. 6. 15.
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. 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 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.