摘要:
Given two arrays, write a function to compute their intersection. Example 1: Input: nums1 = [1,2,2,1], nums2 = [2,2] Output: [2] Example 2: Input: num
阅读全文
posted @ 2016-05-18 23:33
Grandyang
阅读(26095)
推荐(1)
摘要:
Given an unsorted array nums, reorder it such that nums[0] < nums[1] > nums[2] < nums[3].... Notice You may assume all input has valid answer. Example
阅读全文
posted @ 2016-05-17 13:04
Grandyang
阅读(991)
推荐(0)
摘要:
Given an unsorted array nums, reorder it in-place such that nums[0] <= nums[1] >= nums[2] <= nums[3].... Notice Please complete the problem in-place.
阅读全文
posted @ 2016-05-16 23:57
Grandyang
阅读(570)
推荐(0)
摘要:
Given a 2D boolean matrix filled with False and True, find the largest rectangle containing all True and return its area. ExampleGiven a matrix: [ [1,
阅读全文
posted @ 2016-05-15 23:58
Grandyang
阅读(1526)
推荐(0)
摘要:
Given a linked list and two values v1 and v2. Swap the two nodes in the linked list with values v1 and v2. It's guaranteed there is no duplicate value
阅读全文
posted @ 2016-05-14 23:34
Grandyang
阅读(2881)
推荐(1)
摘要:
18.13 Given a list of millions of words, design an algorithm to create the largest possible rectangle of letters such that every row forms a word (rea
阅读全文
posted @ 2016-05-13 23:02
Grandyang
阅读(920)
推荐(0)
摘要:
18.12 Given an NxN matrix of positive and negative integers, write code to find the submatrix with the largest possible sum. 这道求和最大的子矩阵,跟LeetCode上的Max
阅读全文
posted @ 2016-05-12 23:14
Grandyang
阅读(2295)
推荐(0)
摘要:
18.11 Imagine you have a square matrix, where each cell (pixel) is either black or white. Design an algorithm to find the maximum subsquare such that
阅读全文
posted @ 2016-05-11 23:11
Grandyang
阅读(990)
推荐(0)
摘要:
18.10 Given two words of equal length that are in a dictionary, write a method to transform one word into another word by changing only one letter at
阅读全文
posted @ 2016-05-10 23:14
Grandyang
阅读(805)
推荐(0)
摘要:
18.9 Numbers are randomly generated and passed to a method. Write a program to find and maintain the median value as new values are generated. LeetCod
阅读全文
posted @ 2016-05-09 23:07
Grandyang
阅读(659)
推荐(0)
摘要:
18.8 Given a string s and an array of smaller strings T, design a method to search s for each small string in T. 这道题给我们一个字符串s,和一个字符串数组T,让我们找T中的每一个小字符串
阅读全文
posted @ 2016-05-09 02:45
Grandyang
阅读(1076)
推荐(0)
摘要:
5.7 Given a list of words, write a program to find the longest word made of other words in the list. 这道题给了我们一个字符串数组,让我们找到最长的那个单词是由字符串数组中的其他单词组成的,LeetC
阅读全文
posted @ 2016-05-08 02:05
Grandyang
阅读(866)
推荐(0)
摘要:
18.6 Describe an algorithm to find the smallest one million numbers in one billion numbers. Assume that the computer memory can hold all one billion n
阅读全文
posted @ 2016-05-07 05:41
Grandyang
阅读(1010)
推荐(0)
摘要:
Design a Tic-tac-toe game that is played between two players on a n x n grid. You may assume the following rules: A move is guaranteed to be valid and
阅读全文
posted @ 2016-05-06 21:07
Grandyang
阅读(21926)
推荐(0)
摘要:
18.5 You have a large text file containing words. Given any two words, find the shortest distance (in terms of number of words) between them in the fi
阅读全文
posted @ 2016-05-05 21:36
Grandyang
阅读(913)
推荐(0)
摘要:
18.4 Write a method to count the number of 2s between 0 and n. 这道题给了我们一个整数n,让我们求[0,n]区间内所有2出现的个数,比如如果n=20,那么满足题意的是2, 12, 20,那么返回3即可。LeetCode上有一道很类似的题F
阅读全文
posted @ 2016-05-04 21:28
Grandyang
阅读(904)
推荐(0)
摘要:
18.3 Write a method to randomly generate a set of m integers from an array of size n. Each element must have equal probability of being chosen. 这道题让我们
阅读全文
posted @ 2016-05-04 00:57
Grandyang
阅读(688)
推荐(0)
摘要:
在VTK中,我们有时候想要保存vtkImageData类的变量到一幅图片,可以使用如下的实例代码:
阅读全文
posted @ 2016-05-03 12:10
Grandyang
阅读(1866)
推荐(0)
摘要:
Given a non-empty array of integers, return the k most frequent elements. Example 1: Example 2: Input: nums = [1], k = 1 Output: [1] Example 2: Note:
阅读全文
posted @ 2016-05-03 10:42
Grandyang
阅读(29681)
推荐(0)
摘要:
18.2 Write a method to shuffle a deck of cards. It must be a perfect shuffle—in other words, each of the 52! permutations of the deck has to be equall
阅读全文
posted @ 2016-05-03 00:37
Grandyang
阅读(1278)
推荐(0)
摘要:
18.1 Write a function that adds two numbers. You should not use + or any arithmetic operators. 这道题让我们实现两数相加,但是不能用加号或者其他什么数学运算符号,那么我们只能回归计算机运算的本质,位操作Bi
阅读全文
posted @ 2016-05-02 10:03
Grandyang
阅读(5184)
推荐(0)
摘要:
Given a stream of integers and a window size, calculate the moving average of all integers in the sliding window. Example: MovingAverage m = new Movin
阅读全文
posted @ 2016-05-01 05:35
Grandyang
阅读(15604)
推荐(0)
摘要:
17.14 Oh, no! You have just completed a lengthy document when you have an unfortunate Find/Replace mishap. You have accidentally removed all spaces, p
阅读全文
posted @ 2016-04-30 12:20
Grandyang
阅读(862)
推荐(0)
摘要:
A message containing letters from A-Z is being encoded to numbers using the following mapping: 'A' -> 1'B' -> 2...'Z' -> 26Given an encoded message co
阅读全文
posted @ 2016-04-30 12:18
Grandyang
阅读(1189)
推荐(0)
摘要:
Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 16, ...) which sum to n. ExampleGiven n = 12, retur
阅读全文
posted @ 2016-04-30 12:16
Grandyang
阅读(2142)
推荐(0)
摘要:
There is a fence with n posts, each post can be painted with one of the k colors.You have to paint all the posts such that no more than two adjacent f
阅读全文
posted @ 2016-04-30 12:14
Grandyang
阅读(807)
推荐(0)
摘要:
There are a row of n houses, each house can be painted with one of the three colors: red, blue or green. The cost of painting each house with a certai
阅读全文
posted @ 2016-04-30 12:13
Grandyang
阅读(1062)
推荐(0)
摘要:
There are a row of n houses, each house can be painted with one of the k colors. The cost of painting each house with a certain color is different. Yo
阅读全文
posted @ 2016-04-30 12:10
Grandyang
阅读(1030)
推荐(0)
摘要:
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 ex
阅读全文
posted @ 2016-04-30 12:07
Grandyang
阅读(523)
推荐(0)
摘要:
Java和C++中都有关于子字符串的操作,C++中是substr(),Java中是substring(),两者的用法上稍有些区别,首先针对只有一个参数的情况: s.substr(start) 和 s.substring(start) 均表示从start位置开始到结尾的子字符串 而对于有两个参数的情况
阅读全文
posted @ 2016-04-30 00:21
Grandyang
阅读(3226)
推荐(2)
摘要:
After robbing those houses on that street, the thief has found himself a new place for his thievery so that he will not get too much attention. This t
阅读全文
posted @ 2016-04-29 12:38
Grandyang
阅读(860)
推荐(0)
摘要:
You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping yo
阅读全文
posted @ 2016-04-29 12:24
Grandyang
阅读(800)
推荐(0)
摘要:
The thief has found himself a new place for his thievery again. There is only one entrance to this area, called the "root." Besides the root, each hou
阅读全文
posted @ 2016-04-29 11:22
Grandyang
阅读(997)
推荐(0)
摘要:
17.13 Consider a simple node-like data structure called BiNode, which has pointers to two other nodes. The data structure BiNode could be used to repr
阅读全文
posted @ 2016-04-29 10:50
Grandyang
阅读(970)
推荐(0)
摘要:
17.12 Design an algorithm to find all pairs of integers within an array which sum to a specified value. 这道题实际上跟LeetCode上的Two Sum很类似,但是不同的是,那道题限定了只有一组解
阅读全文
posted @ 2016-04-28 10:42
Grandyang
阅读(535)
推荐(0)
摘要:
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
阅读全文
posted @ 2016-04-27 13:54
Grandyang
阅读(834)
推荐(0)
摘要:
17.11 Implement a method rand7() given rand5(). That is, given a method that generates a random number between 0 and 4 (inclusive), write a method tha
阅读全文
posted @ 2016-04-27 12:24
Grandyang
阅读(1147)
推荐(0)
摘要:
17.10 Since XML is very verbose, you are given a way of encoding it where each tag gets mapped to a pre-defined integer value. The language/grammar is
阅读全文
posted @ 2016-04-27 11:13
Grandyang
阅读(976)
推荐(0)
摘要:
You know what, left pad is javascript package and referenced by React: Github link One day his author unpublished it, then a lot of javascript project
阅读全文
posted @ 2016-04-26 13:05
Grandyang
阅读(1419)
推荐(0)
摘要:
Given a nested list of integers, implement an iterator to flatten it. Each element is either an integer, or a list -- whose elements may also be integ
阅读全文
posted @ 2016-04-26 12:47
Grandyang
阅读(1039)
推荐(0)