自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(105)
  • 收藏
  • 关注

转载 【Leetcode】Longest Palindrome

【题目】Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromic substring.【思路】中心检测

2015-09-09 10:25:31 373

转载 【Leetcode】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], [

2015-09-04 11:08:48 324

转载 【Leetcode】Construct binary tree from inorder and postorder traversal

【题目】Given inorder and postorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.【思路】pretty similar with that

2015-09-03 03:10:58 373

转载 【Leetcode】Construct Binary Tree From Inorder and Preorder/Postorder Traversal

【题目】Given preorder and inorder traversal of a tree, construct the binary tree.【思路】Hint:A good way to attempt this question is to work backwards. Approach this question by drawing a binary

2015-09-03 02:13:50 506

转载 【Leetcode】subsets2T

【题目】Given a collection of integers thatmight contain duplicates, nums,return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set must not contai

2015-09-03 00:39:53 304

转载 【Leetcode】maximum Rangtangle in 2D matrix

【题目】Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and return its area.【思路】只能说不明觉厉:The DP solution proceeds row by row, starting f

2015-09-02 11:10:29 306

转载 【Leetcode】Largest Ractangular

【题目】Largest Rectangle in Histogram Total Accepted: 42804 Total Submissions: 188970My SubmissionsQuestion Solution Given n non-negative integers representing the histogram

2015-09-02 11:02:12 275

转载 [Leetcode]Remove duplicates

[timu]Follow up for "Remove Duplicates":What if duplicates are allowed at most twice?For example,Given sorted array nums = [1,1,1,2,2,3],Your function should return length = 5, with

2015-09-02 08:10:54 275

转载 [Leetcode]Word Search

[timu]Given a 2D board and a word, find if the word exists in the grid.The word can be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those horizontal

2015-09-02 07:51:04 268

转载 [Leetcode]sort Color

[timu] Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adja

2015-09-02 03:55:21 252

原创 [Leetcode]Search a 2D matrix

[timu]Search a 2D MatrixTotal Accepted: 52191 Total Submissions: 164580Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the followin

2015-09-02 03:29:54 269

转载 【Leetcode】Set matrix zeros

【题目】【思路】My idea is simple: store states of each row in the first of that row, and store states of each column in the first of that column. Because the state of row0 and the state of column0

2015-09-01 23:10:47 314

转载 【Leetcode】Minimum sum path

【题目】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

2015-09-01 11:30:47 211

转载 【Leetcode】Unique paths 2

【题目】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 respectively

2015-09-01 10:04:16 200

转载 【Leetcode】Spiral Matrix

【题目】Given aninteger n,generate a square matrix filled with elements from 1 to n2 inspiral order.For example,Given n = 3,Youshould return the following matrix:[  [ 1, 2, 3 ],  [ 8, 9, 4 ]

2015-09-01 00:52:31 241

转载 【Leetcode】Merge intervals

【题目】Given a collection ofintervals, merge all overlapping intervals.For example,Given [1,3],[2,6],[8,10],[15,18],return [1,6],[8,10],[15,18].【思路】思路就是,先对进来的这一个list 的inteval进行比较,排序,排序的时候

2015-08-31 22:31:50 240

转载 【Leetcode】Rotate Image

【题目】You are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).【思路】The idea was firstly transpose the matrix and then flip it symmetrically.

2015-08-26 14:31:59 251

转载 【Leetcode】Jump Game 1,2

【题目】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.You

2015-08-26 10:27:45 278

转载 【Leetcode】Rain trapping

【题目】 Given n non-negative integers representing anelevation map where the width of each bar is 1, compute how much water it isable to trap after raining.For example, Given [0,1,0,2,1,0,1,3,2,1

2015-08-25 22:18:54 335

转载 【Leetcode】First Missing Positive

【题目】Given an unsortedinteger array, find the first missing positive integer.For example,Given [1,2,0] return 3,and [3,4,-1,1] return 2.Your algorithm should run in O(n) time and us

2015-08-24 23:21:41 284

转载 【Leetcode】Combination sum 1,2

【题目】【分析】首先,先sort,如果target > 0:【代码】using recursive 这恐怕的 O(n2)...过程:before recursion : [2]before recursion : [2, 2]before recursion : [2, 2, 2]after recursion and remove :

2015-08-24 16:47:10 335

转载 【Leetcode】Search for a range

【题目】【思路】The problem can be simply broken down as two binary searches for the begining and end of the range, respectively:First let's find the left boundary of the range. We ini

2015-08-23 21:09:39 270

转载 【Eclipse】Eclipse快捷键总结

Eclipse中10个最有用的快捷键组合 一个Eclipse骨灰级开发者总结了他认为最有用但又不太为人所知的快捷键组合。通过这些组合可以更加容易的浏览源代码,使得整体的开发效率和质量得到提升。    1. ctrl+shift+r:打开资源    这可能是所有快捷键组合中最省时间的了。这组快捷键可以让你打开你的工作区中任何一个文件,而你只需要按下文件名或mask名中的前几个字母,比如a

2015-08-13 16:33:20 326

转载 【Leetcode】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

2015-08-03 21:38:34 272

转载 【Leetcode】Reorder List

【题目】Given a singly linked list L: L0→L1→…→Ln-1→Ln,reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→…You must do this in-place without altering the nodes' values.For example,Given {1,2,3,4}, reorder it

2015-08-03 20:21:03 254

原创 【Leetcode】Rotate List

【题目】Given a list, rotate the list to the right by k places, where k is non-negative.For example:Given 1->2->3->4->5->NULL and k = 2,return 4->5->1->2->3->NULL.【思路】实质就是n-k个元素挪到了链子的前面, 第

2015-07-29 23:06:14 241

转载 【Leetcode】Kth Largest Element in an Array

【题目】Find the kth 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, retu

2015-07-29 10:07:43 540

转载 【Leetcode】Lowest common treenode in binary tree

【题目】Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined between tw

2015-07-28 22:41:59 471

转载 【Leetcode】Path sum 2

【题目】Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum.For example:Given the below binary tree and sum = 22, 5

2015-07-27 22:44:56 311

转载 【Leetcode】Sort List in O(nlogn) O(1)space

【题目】【思路】First of all, allow me to explain the meaning of strict O(1) auxiliary space complexity.It means the maximum number of memory used by the program, except the memory taken by th

2015-07-27 20:42:43 303

转载 【Leetcode】Delete Node in a LinkedList

【题目】Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.Supposed the linked list is 1 -> 2 -> 3 -> 4 and you are given the third node

2015-07-26 16:47:59 278

转载 【Leetcode】Zigzag Conversion

【题目】The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)P A H N

2015-07-26 13:36:05 319

转载 【Leetcode】Gas Station

【题目】There are N gas stations along a circular route, where the amount of gas at station i is gas[i].You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from sta

2015-07-21 21:00:23 254

转载 【leetcode】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.Hint:Let's

2015-07-21 09:29:39 289

转载 【Leetcode】Implement Queue using Stacks

【题目】Implement the following operations of a queue using stacks.push(x) -- Push element x to the back of queue.pop() -- Removes the element from in front of queue.peek() -- Get the front elem

2015-07-20 22:20:09 318

转载 【Leetcode】Lowest Common Ancestor of a Binary Search Tree

【题目】Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.According to the definition of LCA on Wikipedia: “The lowest common ancestor is defi

2015-07-20 21:05:28 319

转载 【算法】Dijkstra 求最短路径算法

1.dijkstra算法简介Dijkstra算法是由E.W.Dijkstra于1959年提出,又叫迪杰斯特拉算法,它应用了贪心算法模式,是目前公认的最好的求解最短路径的方法。算法解决的是有向图中单个源点到其他顶点的最短路径问题,其主要特点是每次迭代时选择的下一个顶点是标记点之外距离源点最近的顶点。但由于dijkstra算法主要计算从源点到其他所有点的最短路径,所以算法的效率较低。2

2015-07-20 09:24:19 512

转载 【Leetcode】Valid 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 keys less than the nod

2015-07-17 23:26:37 277

转载 【Leetcode】Panlidrome Linked List

【题目】Given a singly linked list, determine if it is a palindrome.Follow up:Could you do it in O(n) time and O(1) space?【思路】panlidrome的话,回文,就是前后是一样的。第一个和最后一个一样, 第二个和倒数第二个一样。linked list

2015-07-17 11:27:36 307

转载 【Leetcode】Merge K Sorted Linked List

【题目】Merge k sorted Linked Lists and return it as one sorted lists. Analyze and describe its complexity .【思路】leetcode clean book【代码】 private static final Comparator listComparator = new

2015-07-16 21:39:48 342

空空如也

空空如也

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

TA关注的人

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