본문 바로가기

math4

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.