- 博客(77)
- 资源 (5)
- 收藏
- 关注
原创 剑指offer 二维数组中的查找
在一个二维数组中,每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序。请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数。javapublic class Solution { public boolean Find(int target, int [][] array) { if (array == null || array.le
2017-10-31 20:29:22 391
原创 Find Minimum in Rotated Sorted Array II
Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).Find the minimum element.The array may contain du
2017-10-31 20:18:08 165
原创 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-10-31 19:35:15 201
原创 240. Search a 2D Matrix II
Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:Integers in each row are sorted in ascending from left to right.Integers in
2017-10-31 14:46:42 173
原创 34. Search for a Range
Given an array of integers sorted in ascending order, find the starting and ending position of a given target value.Your algorithm's runtime complexity must be in the order of O(log n).If the targ
2017-10-31 14:17:57 192
原创 Total Occurrence of Target
Given a target number and an integer array sorted in ascending order. Find the total number of occurrences of target in the array.Have you met this question in a real interview? Yes
2017-10-30 20:45:25 343
原创 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-10-29 21:51:58 355
原创 354. Russian Doll Envelopes
You have a number of envelopes with widths and heights given as a pair of integers (w, h). One envelope can fit into another if and only if both the width and height of one envelope is greater than
2017-10-29 21:05:26 265
原创 300. Longest Increasing Subsequence
Given an unsorted array of integers, find the length of longest increasing subsequence.For example,Given [10, 9, 2, 5, 3, 7, 101, 18],The longest increasing subsequence is [2, 3, 7, 101], ther
2017-10-29 20:14:03 364
原创 674. Longest Continuous Increasing Subsequence
Given an unsorted array of integers, find the length of longest continuous increasing subsequence.Example 1:Input: [1,3,5,4,7]Output: 3Explanation: The longest continuous increasing subseq
2017-10-29 19:59:06 288
原创 Jump Game II
Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Your goal is to
2017-10-29 19:32:53 271
原创 70. Climbing Stairs
You are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?Note: Given n will be a positive
2017-10-29 18:53:00 274
原创 63. Unique Paths II
动态规划的问题,属于坐标型动态规划(二维)Follow up for "Unique Paths":Now consider if some obstacles are added to the grids. How many unique paths would there be?An obstacle and empty space is marked as 1 and 0
2017-10-29 16:46:14 190
原创 62. Unique Paths
A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).The robot can only move either down or right at any point in time. The robot is trying to reach the bo
2017-10-29 16:34:55 175
原创 64. Minimum Path Sum
Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path.Note: You can only move either down or right at
2017-10-29 16:19:59 309
原创 120. Triangle
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the following triangle[ [2], [3,4], [
2017-10-29 11:11:47 196
原创 692. Top K Frequent Words
Given a non-empty list of words, return the k most frequent elements.Your answer should be sorted by frequency from highest to lowest. If two words have the same frequency, then the word with the lo
2017-10-28 16:10:03 778
转载 TreeMap使用简介
原文出自:http://cmsblogs.com/?p=1013。尊重作者的成果,转载请注明出处! 个人站点:http://cmsblogs.com-------------------------------------------------------------------------------------------------------------
2017-10-27 14:39:55 836
原创 658. Find K Closest Elements
Given a sorted array, two integers k and x, find the k closest elements to x in the array. The result should also be sorted in ascending order. If there is a tie, the smaller elements are always p
2017-10-27 14:37:01 287
原创 K Closest Points
Given some points and a point origin in two dimensional space, find k points out of the some points which are nearest to origin.Return these points sorted by distance, if they are same with dist
2017-10-27 14:13:50 526
原创 Merge k Sorted Arrays
Given k sorted integer arrays, merge them into one sorted array.Have you met this question in a real interview? YesExampleGiven 3 sorted arrays:[ [1, 3, 5, 7], [2, 4, 6],
2017-10-26 21:24:07 417
原创 Data Stream Median
Numbers keep coming, return the median of numbers at every time a new number added.Have you met this question in a real interview? YesClarificationWhat's the definition of Medi
2017-10-26 20:57:52 176
原创 Top k Largest Numbers II
Given an integer array, find the top k largest numbers in it.Have you met this question in a real interview? YesExampleGiven [3,10,1000,-99,4,100] and k = 3.Return [1000, 100
2017-10-26 20:00:48 211
原创 378. Kth Smallest Element in a Sorted Matrix
javaclass Solution { public int kthSmallest(int[][] matrix, int k) { if (matrix == null || matrix.length == 0 || matrix[0].length == 0) { return -1; } Queue q
2017-10-26 14:33:51 200
原创 Top k Largest Numbers II
Implement a data structure, provide two interfaces:add(number). Add a new number in the data structure.topk(). Return the top k largest numbers in this data structure. k is given when we creat
2017-10-25 22:56:32 395
原创 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, 12is the sequence of the first 1
2017-10-25 22:43:46 149
原创 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-10-25 21:19:14 168
原创 Longest Consecutive Sequence
Given an unsorted array of integers, find the length of the longest consecutive elements sequence.For example,Given [100, 4, 200, 1, 3, 2],The longest consecutive elements sequence is [1, 2, 3
2017-10-25 20:40:48 215
原创 242. Valid Anagram
Given two strings s and t, write a function to determine if t is an anagram of s.For example,s = "anagram", t = "nagaram", return true.s = "rat", t = "car", return false.Note:You may ass
2017-10-25 19:54:20 199
原创 49. Group Anagrams
Given an array of strings, group anagrams together.For example, given: ["eat", "tea", "tan", "ate", "nat", "bat"], Return:[ ["ate", "eat","tea"], ["nat","tan"], ["bat"]]Note: All in
2017-10-25 19:42:30 263
原创 Anagrams
Given an array of strings, return all groups of strings that are anagrams. NoticeAll inputs will be in lower-caseHave you met this question in a real interview? YesEx
2017-10-25 19:40:41 319
原创 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-10-25 14:06:49 184
原创 146. LRU Cache
必会题目!!! Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and put.get(key) - Get the value (will always be positive) of the key
2017-10-24 21:16:05 181
原创 Rehashing
The size of the hash table is not determinate at the very beginning. If the total size of keys is too large (e.g. size >= capacity / 10), we should double the size of the hash table and rehash every ke
2017-10-24 15:24:28 628
原创 132 Pattern
Given a sequence of n integers a1, a2, ..., an, a 132pattern is a subsequence ai, aj, ak such that i j kand ai ak aj. Design an algorithm that takes a list of n numbers as input and checks whether
2017-10-23 21:59:19 296
原创 Zigzag Iterator ii
Follow up Zigzag Iterator: What if you are given k 1d vectors? How well can your code be extended to such cases? The "Zigzag" order is not clearly defined and is ambiguous for k > 2 cases. If "Z
2017-10-23 21:04:36 325
原创 Zigzag Iterator
Given two 1d vectors, implement an iterator to return their elements alternately.Have you met this question in a real interview? YesExampleGiven two 1d vectors:v1 = [1, 2]v2
2017-10-23 19:42:46 137
原创 341. Flatten Nested List Iterator
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 integers or other lists.Example 1:Given the li
2017-10-23 16:17:24 269
原创 Expression Expand
java思路不复杂,只是代码的量有点大,而且涉及到了一些类型转换。public class Solution { /* * @param s: an expression includes numbers, letters and brackets * @return: a string */ public String expressionE
2017-10-22 15:24:02 197
原创 412. Fizz Buzz
Write a program that outputs the string representation of numbers from 1 to n.But for multiples of three it should output “Fizz” instead of the number and for the multiples of five output “Buzz”.
2017-10-21 15:48:08 184
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人