標籤:: Math

0

Largest Divisible Subset

Largest Divisible SubsetGiven 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

0

Water and Jug Problem

Water and Jug ProblemYou are given two jugs with capacities x and y litres. There is an infinite amount of water supply available. You need to determine whether it is possible to measure exactly z li

0

Count Numbers with Unique Digits

Count Numbers with Unique DigitsGiven a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10^n. For example:1Given n = 2, return 91. (The answer should be the total nu

0

Integer Break

Integer BreakGiven a positive integer n, break it into the sum of at least two positive integers and maximize the product of those integers. Return the maximum product you can get. For example:1Given

0

Bulb Switcher

Bulb SwitcherThere are n bulbs that are initially off. You first turn on all the bulbs. Then, you turn off every second bulb. On the third round, you toggle every third bulb (turning on if it’s off o

0

Super Ugly Number

Super Ugly NumberWrite a program to find the nth super ugly number. Super ugly numbers are positive numbers whose all prime factors are in the given prime list primes of size k. For example, [1, 2, 4

0

Perfect Squares

Perfect SquaresGiven a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 16, …) which sum to n. For example:123Given n = 12, return 3 because 12 = 4 + 4 + 4;G

0

Ugly Number II

Ugly Number IIWrite 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

0

Rectangle Area

Rectangle AreaFind 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 th

0

Sqrt(x)

Sqrt(x)Implement int sqrt(int x). Compute and return the square root of x. 提示 解題應用 Math 規律觀查 Default:123func mySqrt(x int) int {} 解答思路:這題姑且只用最簡單的方式去解決,當然有人用牛頓法的方法來找出結果,不過一開始我就是只用最

0

Permutation Sequence

Permutation SequenceThe set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of the permutations in order,We get the following sequence (ie, for n = 3): “123” “132

0

Pow(x, n)

Pow(x, n)Implement pow(x, n). 提示 解題應用 BinarySearch 二分法 Math 規律觀查 Default:123func myPow(x float64, n int) float64 {} 解答思路:先考慮次方值n只有正數的情況下,如果n是偶數的話x^n就可以變成(x*x)^(n/2),也就是說每次的次方數都可

0

Multiply Strings

Multiply StringsGiven 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 cont

0

Integer to Roman

Integer to RomanGiven an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 to 3999. 提示 解題應用 Math 規律觀查 String 規律觀查 Default:123func intToRoman(num in

0

Add Two Numbers

Add Two NumbersYou are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numb

0

Minimum Moves to Equal Array Elements

Minimum Moves to Equal Array ElementsGiven a non-empty integer array of size n, find the minimum number of moves required to make all array elements equal, where a move is incrementing n - 1 elements

0

Arranging Coins

Arranging CoinsYou have a total of n coins that you want to form in a staircase shape, where every k-th row must have exactly k coins. Given n, find the total number of full staircase rows that can b

0

Add Strings

Add StringsGiven two non-negative integers num1 and num2 represented as string, return the sum of num1 and num2. Note: The length of both num1 and num2 is < 5100. Both num1 and num2 contains only

0

Binary Watch

Binary WatchA binary watch has 4 LEDs on the top which represent the hours (0-11), and the 6 LEDs on the bottom represent the minutes (0-59). Each LED represents a zero or one, with the least signifi

0

Nth Digit

Nth DigitFind the nth digit of the infinite integer sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, … Note: n is positive and will fit within the range of a 32-bit signed integer (n < 231). Example 1:

0

Valid Perfect Square

Valid Perfect SquareGiven a positive integer num, write a function which returns True if num is a perfect square else False. Note: Do not use any built-in library function such as sqrt. Example 1:12

0

Power of Three

Power of ThreeGiven an integer, write a function to determine if it is a power of three. Follow up: Could you do it without using any loop / recursion? 提示 解題應用 Math 腦力激盪 Default:123func isP