自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

  • 博客(228)
  • 收藏
  • 关注

转载 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 th...

2017-06-04 09:41:00 103

转载 378. Kth Smallest Element in a Sorted Matrix

Given anxnmatrix where each of the rows and columns are sorted in ascending order, find the kth smallest element in the matrix. Note that it is the kth smallest element in the sorted order, ...

2017-06-04 08:30:00 96

转载 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], there...

2017-06-03 07:03:00 96

转载 50. Pow(x, n)

Implement pow(x,n). 1 public class Solution { 2 public double myPow(double x, int n) { 3 if(n==0) return 1; 4 if(n<0){ 5 if(n==Integer.MIN_VALUE){ ...

2017-05-27 02:58:00 78

转载 527. Word Abbreviation

Given an array of n distinct non-empty strings, you need to generateminimalpossible abbreviations for every word following rules below. Begin with the first character and then the number of ...

2017-05-26 07:18:00 77

转载 524. Longest Word in Dictionary through Deleting

Given a string and a string dictionary, find the longest string in the dictionary that can be formed by deleting some characters of the given string. If there are more than one possible results, ...

2017-05-26 02:46:00 74

转载 274. H-Index

Given an array of citations (each citation is a non-negative integer) of a researcher, write a function to compute the researcher's h-index. According to thedefinition of h-index on Wikipedia: ...

2017-05-25 08:54:00 62

转载 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 ...

2017-05-25 00:55:00 85

转载 164. Maximum Gap

Given an unsorted array, find the maximum difference between the successive elements in its sorted form. Try to solve it in linear time/space. Return 0 if the array contains less than 2 element...

2017-05-20 02:42:00 78

转载 桶排序

算法原理 桶排序 (Bucket sort)或所谓的箱排序的原理是将数组分到有限数量的桶子里,然后对每个桶子再分别排序(有可能再使用别的排序算法或是以递归方式继续使用桶排序进行排序),最后将各个桶中的数据有序的合并起来。 排序过程: 假设待排序的一组数统一的分布在一个范围中,并将这一范围划分成几个子范围,也就是桶 将待排序的一组数,分档规入这些子桶,并将桶中的数据进行排序 ...

2017-05-20 01:59:00 84

转载 179. Largest Number

Given a list of non negative integers, arrange them such that they form the largest number. For example, given[3, 30, 34, 5, 9], the largest formed number is9534330. Note: The result may be v...

2017-05-20 00:56:00 64

转载 关于Dijkstra 和 Bellman-ford算法的简单理解

两个算法都是跟求图的有源最短路径有关。Dijkstra主要针对的是无负权值节点的图,而Bellman-Ford算法则是可以处理有负权值的有向图的最短路径问题。两者都用到了一个“松弛计算”的方法,也就是在遍历图的顶点和边的过程中修改距离数组的值,从而来找出最短路径。 Dijkstra算法针对无负权值的图,求源点到某特定点的最短距离。大概的思路是: 将图的顶点分成两个集合S,...

2017-04-01 07:21:00 910

转载 What is pseudopolynomial time? How does it differ from polynomial time?

To understand the difference between polynomial time and pseudopolynomial time, we need to start off by formalizing what "polynomial time" means. The common intuition for polynomial time is "tim...

2017-04-01 06:35:00 185

转载 备忘录方法与动态规划比较

动态规划算法的基本要素:1 最优子结构性质当问题的最优解包含了其子问题的最优解时,称该问题具有最优子结构性质。2 重叠子问题性质动态规划算法对每个问题只解一次,将其解保存在一个表格中,当再次需要解此问题时,用常数时间查看一下结果。因此,用动态规划算法通常只需要多项式时间。 备忘录方法:•用一个表格来保存已解决的子问题的答案,用的时候查表即可。•采用的递归方式是自顶向下。•...

2017-03-28 07:01:00 578

转载 285. Inorder Successor in BST

Given a binary search tree and a node in it, find the in-order successor of that node in the BST. Note: If the given node has no in-order successor in the tree, returnnull. 本题要求按中序遍历节点p的下一个...

2017-03-24 11:35:00 75

转载 222. Count Complete Tree Nodes

Given acompletebinary tree, count the number of nodes. Definition of a complete binary tree fromWikipedia:In a complete binary tree every level, except possibly the last, is completely filled...

2017-03-24 08:39:00 65

转载 270. Closest Binary Search Tree Value

Given a non-empty binary search tree and a target value, find the value in the BST that is closest to the target. Note: Given target value is a floating point. You are guaranteed to have onl...

2017-03-24 07:13:00 101

转载 272. Closest Binary Search Tree Value II

Given a non-empty binary search tree and a target value, findkvalues in the BST that are closest to the target. Note: Given target value is a floating point. You may assumekis always val...

2017-03-24 02:57:00 61

转载 230. Kth Smallest Element in a BST

Given a binary search tree, write a functionkthSmallestto find thekth smallest element in it. Note:You may assume k is always valid, 1 ≤ k ≤ BST's total elements. Follow up:What if the BST ...

2017-03-24 01:44:00 62

转载 173. Binary Search Tree Iterator

Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST. Callingnext()will return the next smallest number in the BST. Note:next(...

2017-03-24 01:10:00 55

转载 145. Binary Tree Postorder Traversal

Given a binary tree, return thepostordertraversal of its nodes' values. For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3 return[3,2,1]. Note:Recursive soluti...

2017-03-23 11:32:00 67

转载 98. Validate Binary Search Tree

Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as follows: The left subtree of a node contains only nodes with keysless thanthe node's key...

2017-03-23 10:28:00 55

转载 255. Verify Preorder Sequence in Binary Search Tree

Given an array of numbers, verify whether it is the correct preorder traversal sequence of a binary search tree. You may assume each number in the sequence is unique. Follow up:Could you do it ...

2017-03-23 08:42:00 54

转载 144. Binary Tree Preorder Traversal

Given a binary tree, return thepreordertraversal of its nodes' values. For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3 return[1,2,3]. Note:Recursive solutio...

2017-03-23 06:40:00 52

转载 94. Binary Tree Inorder Traversal

Given a binary tree, return theinordertraversal of its nodes' values. For example:Given binary tree[1,null,2,3], 1 \ 2 / 3 return[1,3,2]. Note:Recursive solut...

2017-03-23 06:06:00 54

转载 311. Sparse Matrix Multiplication

Given twosparse matricesAandB, return the result ofAB. You may assume thatA's column number is equal toB's row number. Example: A = [ [ 1, 0, 0], [-1, 0, 3] ] B = [ [ 7, 0,...

2017-03-23 02:48:00 48

转载 389. Find the Difference

Given two stringssandtwhich consist of only lowercase letters. Stringtis generated by random shuffling stringsand then add one more letter at a random position. Find the letter that was...

2017-03-23 01:09:00 55

转载 java中Math.abs(-2147483648)的返回值应该是什么?

我觉得这是一个非常有意思的问题,Math.abs(-2147483648)的返回值应该是什么? java计算结果 为什么没有得到正数结果呢? 首先我们先看下java区分整数正负的原理。在二进制的情况下,java使用0和1来代表正和负,最高位——左面第一位为1代表负数,最高位为0就代表正数。在32位的int二进制表示里,最高位是预留出来表示正负号的。 我们知道java ...

2017-03-23 00:34:00 591

转载 166. Fraction to Recurring Decimal

Given two integers representing the numerator and denominator of a fraction, return the fraction in string format. If the fractional part is repeating, enclose the repeating part in parentheses....

2017-03-22 12:29:00 46

转载 299. Bulls and Cows

You are playing the followingBulls and Cowsgame with your friend: You write down a number and ask your friend to guess what the number is. Each time your friend makes a guess, you provide a hin...

2017-03-22 10:50:00 61

转载 463. Island Perimeter

You are given a map in form of a two-dimensional integer grid where 1 represents land and 0 represents water. Grid cells are connected horizontally/vertically (not diagonally). The grid is comple...

2017-03-22 09:33:00 48

转载 291. Word Pattern II

Given apatternand a stringstr, find ifstrfollows the same pattern. Herefollowmeans a full match, such that there is a bijection between a letter inpatternand anon-emptysubstring inst...

2017-03-22 07:37:00 60

转载 290. Word Pattern

Given apatternand a stringstr, find ifstrfollows the same pattern. Herefollowmeans a full match, such that there is a bijection between a letter inpatternand anon-emptyword instr. E...

2017-03-22 06:07:00 45

转载 205. Isomorphic Strings

Given two stringssandt, determine if they are isomorphic. Two strings are isomorphic if the characters inscan be replaced to gett. All occurrences of a character must be replaced with ano...

2017-03-22 05:54:00 50

转载 516. Longest Palindromic Subsequence

Given a string s, find the longest palindromic subsequence's length in s. You may assume that the maximum length of s is 1000. Example 1:Input: "bbbab" Output: 4 One possible longest pal...

2017-03-22 02:58:00 49

转载 递归和迭代的区别

递归的基本概念:程序调用自身的编程技巧称为递归,是函数自己调用自己. 一个函数在其定义中直接或间接调用自身的一种方法,它通常把一个大型的复杂的问题转化为一个与原问题相似的规模较小的问题来解决,可以极大的减少代码量.递归的能力在于用有限的语句来定义对象的无限集合. 使用递归要注意的有两点: 1)递归就是在过程或函数里面调用自身; 2)在使用递归时,必须有一个明确的递归结束条件,...

2017-03-22 02:56:00 52

转载 336. Palindrome Pairs

Given a list ofuniquewords, find all pairs ofdistinctindices(i, j)in the given list, so that the concatenation of the two words, i.e.words[i] + words[j]is a palindrome. Example 1:Givenw...

2017-03-22 01:49:00 51

转载 选取第K大数的快速选择算法和注意事项

快速选择算法,是一种能在大致O(N)的时间内选取数组中第k大或者k小的算法.其基本思路与快速排序算法类似,也是分治的思想. 其实这个算法是个基础算法,但是不常用,所以今天编的时候错了POJ2388,才有了这篇文章. 执行Partition算法(就是那个快排里将区间内所有数划分为小的一部分和大的一部分的过程) 判断第k大的数是在小的部分还是大的部分 递归,直到区间足够小,返回结...

2017-03-21 08:16:00 105

转载 215. Kth Largest Element in an Array

Find thekth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element. For example,Given[3,2,1,5,6,4]and k = 2, return 5....

2017-03-21 07:56:00 43

转载 347. Top K Frequent Elements

Given a non-empty array of integers, return thekmost frequent elements. For example,Given[1,1,1,2,2,3]and k = 2, return[1,2]. Note: You may assumekis always valid, 1 ≤k≤ number o...

2017-03-21 06:25:00 50

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除