- 博客(50)
- 收藏
- 关注
原创 链式前向星
摘自 http://www.cnblogs.com/LQ-double/p/5971323.html https://www.baidu.com/link?url=mJSzzTO-saQexGiBxZDXQzBLZArVveITjVSqBnLXU-_wixEOCZagAoy6VbvYqQs0&wd=&eqid=e579ac6d00002777000000065829af79
2016-11-14 20:38:52 333
原创 全排列散列
//x为排列的排名,范围[0~n!-1] //n为字符的个数 public static String intToArray(int x,int n) { boolean[] used=new boolean[n+1]; StringBuilder sb=new StringBuilder(); for(int i=1;i<=n;i++) { int temp=x/fa
2016-11-14 15:32:32 324
原创 素数晒法、素数Rabin测试、快速幂取模
素数筛法,产生num以内的素数表 public static int makePrimes(int primes[], int num) { int i, j, cnt; primes[0] = 2; primes[1] = 3; for(i = 5, cnt = 2; i < num; i += 2) { boolean flag = true; for(j
2016-11-14 10:43:47 691
原创 欧拉函数
摘自 http://blog.csdn.net/once_hnu/article/details/6302868 欧拉函数 对正整数n,欧拉函数是少于或等于n的数中与n互质的数的数目。例如euler(8)=4,因为1,3,5,7均和8互质。 Euler函数表达通式:euler(x)=x(1-1/p1)(1-1/p2)(1-1/p3)(1
2016-11-14 10:28:25 249
转载 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
2016-11-13 16:41:12 357
原创 452. Minimum Number of Arrows to Burst Balloons
There are a number of spherical balloons spread in two-dimensional space. For each balloon, provided input is the start and end coordinates of the horizontal diameter. Since it's horizontal, y-coordin
2016-11-13 15:30:26 217
原创 447. Number of Boomerangs
Given n points in the plane that are all pairwise distinct, a "boomerang" is a tuple of points (i, j, k) such that the distance between iand j equals the distance between i and k (the order of t
2016-11-13 11:30:41 242
原创 446. Arithmetic Slices II - Subsequence
A sequence of numbers 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 sequen
2016-11-13 09:51:10 443
原创 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.
2016-11-09 22:12:01 218
转载 440. K-th Smallest in Lexicographical Order
Given integers n and k, find the lexicographically k-th smallest integer in the range from 1 to n. Note: 1 ≤ k ≤ n ≤ 109. Example: Input: n: 13 k: 2 Output: 10 Explanation: The lexicograp
2016-11-09 22:08:29 663
原创 438. Find All Anagrams in a String
Given a string s and a non-empty string p, find all the start indices of p's anagrams in s. Strings consists of lowercase English letters only and the length of both strings s and p will not be lar
2016-11-09 22:04:24 266
原创 437. Path Sum III
You are given a binary tree in which each node contains an integer value. Find the number of paths that sum to a given value. The path does not need to start or end at the root or a leaf, but it
2016-11-09 21:51:19 183
原创 436. Find Right Interval
Given a set of intervals, for each of the interval i, check if there exists an interval j whose start point is bigger than or equal to the end point of the interval i, which can be called that j is on
2016-11-09 21:45:33 234
原创 435. Non-overlapping Intervals
Given a collection of intervals, find the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping. Note: You may assume the interval's end point is alw
2016-11-09 21:35:14 273
原创 432. All O`one Data Structure
Implement a data structure supporting the following operations: Inc(Key) - Inserts a new key with value 1. Or increments an existing key by 1. Key is guaranteed to be a non-empty string.Dec(Key
2016-11-09 21:15:43 659
原创 424. Longest Repeating Character Replacement
Given a string that consists of only uppercase English letters, you can replace any letter in the string with another letter at most k times. Find the length of a longest substring containing all repe
2016-11-09 21:12:13 445
原创 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
2016-11-09 20:36:47 278
转载 421. Maximum XOR of Two Numbers in an Array
Given a non-empty array of numbers, a0, a1, a2, … , an-1, where 0 ≤ ai < 231. Find the maximum result of ai XOR aj, where 0 ≤ i, j n. Could you do this in O(n) runtime? Example: Input:
2016-11-09 20:31:46 202
转载 420. Strong Password Checker
A password is considered strong if below conditions are all met: It has at least 6 characters and at most 20 characters.It must contain at least one lowercase letter, at least one uppercase letter,
2016-11-09 20:27:22 707
原创 419. Battleships in a Board
Given an 2D board, count how many different battleships are in it. The battleships are represented with 'X's, empty slots are represented with '.'s. You may assume the following rules: You receiv
2016-11-09 20:22:29 276
原创 417. Pacific Atlantic Water Flow
Given an m x n matrix of non-negative integers representing the height of each unit cell in a continent, the "Pacific ocean" touches the left and top edges of the matrix and the "Atlantic ocean" tou
2016-11-09 20:11:37 196
原创 416. Partition Equal Subset Sum
Given a non-empty array containing only positive integers, find if the array can be partitioned into two subsets such that the sum of elements in both subsets is equal. Note: Each of the array
2016-11-09 19:59:08 167
原创 415. Add Strings
Given two non-negative numbers 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.B
2016-11-09 19:53:14 159
原创 414. Third Maximum Number
Given a non-empty array of integers, return the third maximum number in this array. If it does not exist, return the maximum number. The time complexity must be in O(n). Example 1: Input: [3, 2,
2016-11-09 19:49:32 224
原创 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 sequenc
2016-11-09 19:33:44 185
原创 410. Split Array Largest Sum
Given an array which consists of non-negative integers and an integer m, you can split the array into m non-empty continuous subarrays. Write an algorithm to minimize the largest sum among these m sub
2016-11-09 19:21:03 409
原创 409. Longest Palindrome
Given a string which consists of lowercase or uppercase letters, find the length of the longest palindromes that can be built with those letters. This is case sensitive, for example "Aa" is not con
2016-11-09 16:58:51 170
转载 407. Trapping Rain Water II
Given an m x n matrix of positive integers representing the height of each unit cell in a 2D elevation map, compute the volume of water it is able to trap after raining. Note: Both m and n are l
2016-11-09 16:55:43 472
转载 406. Queue Reconstruction by Height
Suppose you have a random list of people standing in a queue. Each person is described by a pair of integers (h, k), where h is the height of the person and k is the number of people in front of t
2016-11-09 16:49:29 237
原创 405. Convert a Number to Hexadecimal
Given an integer, write an algorithm to convert it to hexadecimal. For negative integer, two’s complement method is used. Note: All letters in hexadecimal (a-f) must be in lowercase.The hexade
2016-11-09 16:46:14 154
转载 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: Input
2016-11-09 16:40:31 172
原创 399. Evaluate Division
Equations are given in the format A / B = k, where A and B are variables represented as strings, and k is a real number (floating point number). Given some queries, return the answers. If the answ
2016-11-09 16:18:26 291
原创 398. Random Pick Index
Given an array of integers with possible duplicates, randomly output the index of a given target number. You can assume that the given target number must exist in the array. Note: The array size c
2016-11-09 16:00:19 186
原创 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
2016-11-09 15:44:13 202
原创 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:
2016-11-09 15:41:05 138
转载 395. Longest Substring with At Least K Repeating Characters
Find the length of the longest substring T of a given string (consists of lowercase letters only) such that every character in T appears no less than k times. Example 1: Input: s = "aaabb", k =
2016-11-09 15:18:49 167
原创 394. Decode String
Given an encoded string, return it's decoded string. The encoding rule is: k[encoded_string], where the encoded_string inside the square brackets is being repeated exactly k times. Note thatk is
2016-11-09 11:48:13 157
原创 393. UTF-8 Validation
A character in UTF8 can be from 1 to 4 bytes long, subjected to the following rules: For 1-byte character, the first bit is a 0, followed by its unicode code.For n-bytes character, the first n-bits
2016-11-09 11:34:39 340
原创 392. Is Subsequence
Given a string s and a string t, check if s is subsequence of t. You may assume that there is only lower case English letters in both s and t. t is potentially a very long (length ~= 500,000) strin
2016-11-09 11:30:39 142
原创 391. Perfect Rectangle
Given N axis-aligned rectangles where N > 0, determine if they all together form an exact cover of a rectangular region. Each rectangle is represented as a bottom-left point and a top-right point.
2016-11-09 11:09:45 205
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人