Marcy Blog

Failed to be a geek

Problem: Integer to English Words

Question Convert a non-negative integer to its english words representation. Given input is guaranteed to be less than 231 - 1. Example 1: Input: 123 Output: "One Hundred Twenty Three" Example 2...

Problem: Pow(x, n)

Question Implement pow(x, n), which calculates x raised to the power n (xn). Example 1: Input: 2.00000, 10 Output: 1024.00000 Example 2: Input: 2.10000, 3 Output: 9.26100 Example 3: Input: 2.00...

Problem: Power of Two

Question Given an integer, write a function to determine if it is a power of two. Solution TODO Code class Solution { public boolean isPowerOfTwo(int n) { if(n<=0) return false; ...

Problem: Multiply Strings

Question Given two non-negative integers num1 and num2 represented as strings, return the product of num1 and num2. Note: The length of both num1 and num2 is < 110. Both num1 and num2 co...

Problem: Rectangle Area

Question Find the total area covered by two rectilinear rectangles in a 2D plane. Each rectangle is defined by its bottom left corner and top right corner as shown in the figure. Assume that t...

Problem: Rectangle Overlap

Question A rectangle is represented as a list [x1, y1, x2, y2], where (x1, y1) are the coordinates of its bottom-left corner, and (x2, y2) are the coordinates of its top-right corner. Two rectang...

Problem: Ugly Number II

Question Write a program to find the n-th ugly number. Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 1, 2, 3, 4, 5, 6, 8, 9, 10, 12 is the sequence of t...

Problem: Ugly Number

Question Write a program to check whether a given number is an ugly number. Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 6, 8 are ugly while 14 is not ...

Problem: String to Integer (atoi)

Question Implement atoi to convert a string to an integer. Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possib...

Problem: Count Primes

Question Count the number of prime numbers less than a non-negative number, n. Solution TODO Code class Solution { public int countPrimes(int n) { if(n<=2) return 0; List&...