본문 바로가기

전체 글137

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. Search in a Binary Search Tree Problem: Given the root node of a binary search tree (BST) and a value. You need to find the node in the BST that the node's value equals the given value. Return the subtree rooted with that node. If such node doesn't exist, you should return NULL. For example, In the example above, if we want to search the value 5, since there is no node with value 5, we should return NULL. Note that an empty t.. 2020. 6. 16.
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 238. Product of Array Except Self [Array] Problem: Given an array nums of n integers where n > 1, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i]. Example: Input: [1,2,3,4] Output: [24,12,8,6] Constraint: It's guaranteed that the product of the elements of any prefix or suffix of the array (including the whole array) fits in a 32 bit integer. Note: Please solve it without div.. 2020. 6. 16.
LeetCode. Cheapest Flights Within K Stops Problem: There are n cities connected by m flights. Each flight starts from city u and arrives at v with a price w. Now given all the cities and flights, together with starting city src and the destination dst, your task is to find the cheapest price from src to dst with up to k stops. If there is no such route, output -1. -Summary- Using Dijkstra's Algorithm -Debugging- leetcode.com/problems/ch.. 2020. 6. 15.
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.