
Math
文章平均质量分 67
zshouyi
这个作者很懒,什么都没留下…
展开
-
149. Max Points on a Line
Given n points on a 2D plane, find the maximum number of points that lie on the same straight line.这道题应该注意只要是在一条直线上就算。第一反应是用HashMap来存斜率,但是如果double精确到小数点后好多位之后就趋于相等,key值就相等了,所以一般不要用double作key。这里可以用原创 2017-08-12 04:46:12 · 316 阅读 · 0 评论 -
397. Integer Replacement
Given a positive integer n and you can do operations as follow:If n is even, replace n with n/2.If n is odd, you can replace n with either n + 1 or n - 1.What is the minimum number o原创 2017-03-31 03:06:40 · 353 阅读 · 0 评论 -
423. Reconstruct Original Digits from English
Given a non-empty string containing an out-of-order English representation of digits 0-9, output the digits in ascending order.Note:Input contains only lowercase English letters.Input is g原创 2017-03-31 02:28:33 · 234 阅读 · 0 评论 -
365. Water and Jug Problem
You 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 litres using these two原创 2017-03-30 08:26:35 · 662 阅读 · 0 评论 -
413. Arithmetic Slices
A sequence of number is called arithmetic if it consists of at least three elements and if the difference between any two consecutive elements is the same.For example, these are arithmetic seque原创 2017-03-30 06:56:15 · 256 阅读 · 0 评论 -
367. Valid Perfect Square
Given 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:Input: 16Return原创 2017-03-30 01:50:33 · 333 阅读 · 0 评论 -
357. Count Numbers with Unique Digits
Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x n.Example:Given n = 2, return 91. (The answer should be the total numbers in the range of 0 ≤ x [11,22,33,44,原创 2017-03-23 07:20:04 · 307 阅读 · 0 评论 -
372. Super Pow
Your task is to calculate ab mod 1337 where a is a positive integer and b is an extremely large positive integer given in the form of an array.Example1:a = 2b = [3]Result: 8Example原创 2017-03-23 06:52:14 · 337 阅读 · 0 评论 -
60. Permutation Sequence
The 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""213""231""3原创 2017-03-23 02:10:15 · 229 阅读 · 0 评论 -
368. Largest Divisible Subset
Given 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 multiple solution原创 2017-03-29 03:01:26 · 200 阅读 · 0 评论 -
264. Ugly Number II
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 the first原创 2017-03-22 08:07:33 · 267 阅读 · 0 评论 -
247. Strobogrammatic Number II
A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside down).Find all strobogrammatic numbers that are of length = n. For example,Given n = 2, re原创 2017-03-31 11:24:34 · 428 阅读 · 0 评论 -
313. Super Ugly Number
Write 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, 7, 8, 13,原创 2017-03-24 11:12:17 · 251 阅读 · 0 评论 -
360. Sort Transformed Array
Given a sorted array of integers nums and integer values a, b and c. Apply a function of the form f(x) = ax2 + bx + c to each element x in the array. The returned array must be in sorted order.原创 2017-04-01 01:48:27 · 559 阅读 · 0 评论 -
335. Self Crossing
You are given an array x of n positive numbers. You start at point (0,0) and moves x[0] metres to the north, then x[1] metres to the west, x[2] metres to the south, x[3] metres to the east and s原创 2017-08-18 03:00:52 · 494 阅读 · 0 评论 -
553. Optimal Division
Given a list of positive integers, the adjacent integers will perform the float division. For example, [2,3,4] -> 2 / 3 / 4.However, you can add any number of parenthesis at any position to change原创 2017-05-06 04:52:23 · 570 阅读 · 0 评论 -
507. Perfect Number
We define the Perfect Number is a positive integer that is equal to the sum of all its positive divisors except itself. Now, given an integer n, write a function that returns true when it is a per原创 2017-04-04 09:58:00 · 1620 阅读 · 0 评论 -
523. Continuous Subarray Sum
Given a list of non-negative numbers and a target integer k, write a function to check if the array has a continuous subarray of size at least 2 that sums up to the multiple of k, that is, sums up t原创 2017-04-04 09:44:19 · 445 阅读 · 0 评论 -
535. Encode and Decode TinyURL
Note: This is a companion problem to the System Design problem: Design TinyURL.TinyURL is a URL shortening service where you enter a URL such as https://leetcode.com/problems/design-tinyurl an原创 2017-04-02 04:26:36 · 1081 阅读 · 0 评论 -
537. Complex Number Multiplication
Given two strings representing two complex numbers.You need to return a string representing their multiplication. Note i2 = -1 according to the definition.Example 1:Input: "1+1i", "1+1i"O原创 2017-04-02 03:30:22 · 975 阅读 · 0 评论 -
469. Convex Polygon
Given a list of points that form a polygon when joined sequentially, find if this polygon is convex (Convex polygon definition).Note:There are at least 3 and at most 10,000 points.Coordinate原创 2017-04-02 03:13:48 · 764 阅读 · 0 评论 -
319. Bulb Switcher
There 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 or turning off原创 2017-03-16 14:54:40 · 518 阅读 · 0 评论 -
296. Best Meeting Point
A group of two or more people wants to meet and minimize the total travel distance. You are given a 2D grid of values 0 or 1, where each 1 marks the home of someone in the group. The distance is calcu原创 2017-04-01 02:39:42 · 309 阅读 · 0 评论 -
462. Minimum Moves to Equal Array Elements II
Given a non-empty integer array, find the minimum number of moves required to make all array elements equal, where a move is incrementing a selected element by 1 or decrementing a selected element by原创 2017-04-01 02:33:11 · 578 阅读 · 0 评论 -
356. Line Reflection
Given n points on a 2D plane, find if there is such a line parallel to y-axis that reflect the given points.Example 1:Given points = [[1,1],[-1,1]], return true.Example 2:Given poi原创 2017-03-12 09:51:01 · 316 阅读 · 0 评论 -
343. Integer Break
Given 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, given n = 2, ret原创 2017-03-21 15:34:17 · 246 阅读 · 0 评论 -
396. Rotate Function
Given an array of integers A and let n to be its length.Assume Bk to be an array obtained by rotating the array A k positions clock-wise, we define a "rotation function" F on A as follow:原创 2017-01-14 12:35:30 · 225 阅读 · 0 评论 -
453. Minimum Moves to Equal Array Elements
Given 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 by 1.Example:Input:[1,2,3]Ou原创 2017-01-14 11:50:23 · 195 阅读 · 0 评论 -
168. Excel Sheet Column Title
Given a positive integer, return its corresponding column title as appear in an Excel sheet.For example: 1 -> A 2 -> B 3 -> C ... 26 -> Z 27 -> AA 28 -> AB Credits原创 2017-01-14 10:01:11 · 358 阅读 · 0 评论 -
231. Power of Two
Given an integer, write a function to determine if it is a power of two.Credits:Special thanks to @jianchao.li.fighter for adding this problem and creating all test cases.判断一个数是不是2的次幂,从bit入手。如原创 2017-01-14 09:02:58 · 192 阅读 · 0 评论 -
223. Rectangle Area
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 the tota原创 2017-01-14 08:39:05 · 217 阅读 · 0 评论 -
326. Power of Three
Given 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?Credits:Special thanks to @dietpepsi for adding this原创 2017-01-14 07:59:16 · 282 阅读 · 0 评论 -
246. Strobogrammatic Number
A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside down).Write a function to determine if a number is strobogrammatic. The number is represented as原创 2017-01-07 08:19:02 · 276 阅读 · 0 评论 -
66. Plus One
Given a non-negative number represented as an array of digits, plus one to the number.The digits are stored such that the most significant digit is at the head of the list.中文:给出一个由整型数组表示的非负数字,将这原创 2016-12-27 10:12:03 · 360 阅读 · 0 评论 -
263. Ugly Number
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 ugly si原创 2017-01-04 07:05:05 · 214 阅读 · 0 评论 -
204. Count Primes
Description:Count the number of prime numbers less than a non-negative number, n.Credits:Special thanks to @mithmatt for adding this problem and creating all test cases.统计小于n 的质数的个数。创建大小n原创 2017-01-04 06:09:37 · 221 阅读 · 0 评论 -
415. Add Strings
Given 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 Both num1 and num2 contains only digits 0-9.原创 2017-01-15 08:24:56 · 274 阅读 · 0 评论 -
400. Nth Digit
Find 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 31).Example 1:Inpu原创 2017-01-15 15:29:08 · 282 阅读 · 0 评论 -
441. Arranging Coins
You 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 be formed.原创 2017-01-16 09:38:03 · 293 阅读 · 0 评论 -
29. Divide Two Integers
Divide two integers without using multiplication, division and mod operator.If it is overflow, return MAX_INT.1、让divisor一直乘22、如果divisor>dividend,则用dividend - 上一个divisor3、余下的数继续重复1,2步这里有两种情原创 2017-03-21 10:04:10 · 307 阅读 · 0 评论