自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 Minimum Path Sum

Problem: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 do

2014-10-06 22:49:37 410

原创 Merge Two Sorted Lists

Problem:Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.Solution:/** * Definition for

2014-10-06 22:14:14 364

原创 Add Binary

Problem:Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".时间复杂度为O(max(n,m))。Solution:public class Solution {    public S

2014-10-06 22:12:52 392

原创 Plus One

Problem:Given a non-negative number represented as an array of digits, plus one to the number.The digits are stored such that the most significant digit is at the head of the list.问题实质就是实现

2014-10-06 14:30:32 331

原创 Text Justification

Problem:Given an array of words and a length L, format the text such that each line has exactly L characters and is fully (left and right) justified.You should pack your words in a greedy ap

2014-10-06 14:08:48 336

原创 Sqrt(x)

Problem:Implement int sqrt(int x).Compute and return the square root of x.使用了逐比特确认法。该算法的详细解释见维基百科:http://en.wikipedia.org/wiki/Methods_of_computing_square_roots下面做粗略描述。相关公式也是从维基摘录过

2014-10-05 23:58:13 408

原创 Binary Tree Level Order Traversal

Problem:Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).For example:Given binary tree {3,9,20,#,#,15,7}, 3 / \

2014-10-03 12:53:23 305

原创 Construct Binary Tree from Inorder and Postorder Traversal

Problem:Given inorder and postorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.Solution:/** * Definition for bina

2014-10-03 12:51:55 465

原创 Binary Tree Zigzag Level Order Traversal

Problem:Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between).For example:

2014-10-03 12:51:15 332

原创 Convert Sorted Array to Binary Search Tree

Problem:Given an array where elements are sorted in ascending order, convert it to a height balanced BST.先序遍历。Solution:/** * Definition for binary tree * public class TreeNod

2014-10-03 12:50:44 330

原创 Binary Tree Level Order Traversal II

Problem:Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root).For example:Given binary tree {3,9,

2014-10-03 12:49:42 373

原创 Convert Sorted List to Binary Search Tree

Problem:Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.递归求解,Solution1是原创版本,先序遍历,时间复杂度nlog(n)。Solution2是讨论区大牛版本,中序遍历,时间复杂度n。

2014-10-03 12:49:35 406

原创 Balanced Binary Tree

Problem:Given a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every no

2014-10-03 12:48:37 359

原创 Minimum Depth of Binary Tree

Problem:Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.Solution:/** *

2014-10-03 12:46:24 325

原创 Flatten Binary Tree to Linked List

Problem:Given a binary tree, flatten it to a linked list in-place.For example,Given 1 / \ 2 5 / \ \ 3 4 6The flattened tree should look

2014-10-03 12:45:58 349

原创 Path Sum II

Problem: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

2014-10-03 12:45:19 311

原创 Distinct Subsequences

Problem:Given a string S and a string T, count the number of distinct subsequences of T in S.A subsequence of a string is a new string which is formed from the original string by deleting so

2014-10-03 12:44:30 316

原创 Populating Next Right Pointers in Each Node II

Problem:Follow up for problem "Populating Next Right Pointers in Each Node".What if the given tree could be any binary tree? Would your previous solution still work?Note:You may only

2014-10-03 12:43:19 367

原创 Populating Next Right Pointers in Each Node

Problem:Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each next pointer to point to its n

2014-10-03 12:41:32 615

原创 Pascal's Triangle II

Problem:Given an index k, return the kth row of the Pascal's triangle.For example, given k = 3,Return [1,3,3,1].Note:Could you optimize your algorithm to use only O(k) extra space?

2014-10-03 12:40:43 293

原创 Triangle

Problem: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],

2014-10-03 12:38:50 317

原创 Pascal's Triangle

Problem:Given numRows, generate the first numRows of Pascal's triangle.For example, given numRows = 5,Return[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1]]杨辉三角。Sol

2014-10-03 12:38:11 325

原创 Best Time to Buy and Sell Stock III

Problem:Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete at most two transactions.N

2014-10-03 12:37:27 320

原创 Word Ladder II

Problem:Given two words (start and end), and a dictionary, find all shortest transformation sequence(s) from start to end, such that:Only one letter can be changed at a timeEach intermediate

2014-10-03 12:35:47 456

原创 Best Time to Buy and Sell Stock II

Problem:Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete as many transactions as you li

2014-10-03 12:33:39 306

原创 Best Time to Buy and Sell Stock

Problem:Say you have an array for which the ith element is the price of a given stock on day i.If you were only permitted to complete at most one transaction (ie, buy one and sell one share

2014-10-03 12:27:07 262

原创 Binary Tree Maximum Path Sum

Problem:Given a binary tree, find the maximum path sum.The path may start and end at any node in the tree.For example:Given the below binary tree, 1 / \ 2 3

2014-10-02 23:55:06 390

原创 Word Ladder

Problem:Given two words (start and end), and a dictionary, find the length of shortest transformation sequence from start to end, such that:Only one letter can be changed at a timeEach inter

2014-10-02 23:54:16 318

原创 Longest Consecutive Sequence

Problem: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 sequen

2014-10-02 23:53:29 296

原创 Surrounded Regions

Problem:Given a 2D board containing 'X' and 'O', capture all regions surrounded by 'X'.A region is captured by flipping all 'O's into 'X's in that surrounded region.For example,X X

2014-10-02 23:50:15 354

原创 Sum Root to Leaf Numbers

Problem:Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number.An example is the root-to-leaf path 1->2->3 which represents the number 123.

2014-10-02 23:50:15 357

原创 Palindrome Partitioning II

Problem:Given a string s, partition s such that every substring of the partition is a palindrome.Return the minimum cuts needed for a palindrome partitioning of s.For example, given s = 

2014-10-02 23:47:46 320

原创 Palindrome Partitioning

Problem:Given a string s, partition s such that every substring of the partition is a palindrome.Return all possible palindrome partitioning of s.For example, given s = "aab",Return

2014-10-02 23:46:39 340

原创 Clone Graph

Problem:Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors.OJ's undirected graph serialization:Nodes are labeled uniquely.We use # as a se

2014-10-02 23:45:43 383

原创 Gas Station

Problem: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 trave

2014-10-02 23:44:52 360

原创 百度2015校招笔试

地点:清华5教5101,时间:19:00-21:00,职位:软件开发工程师简答题:1. 说说栈和队列的区别,分别给出3个常用的接口。2. 简述什么是多态,用C++举例说明。3. TCP四次挥手的过程及TIME_WAIT的原因和作用。算法题:1. 用C/C++写一个函数,实现字符串反转,不能用任何系统函数,且时间复杂度最小。char

2014-10-02 23:41:55 620

原创 Scramble String

Problem:Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively.Below is one possible representation of s1 = "great": great

2014-10-02 23:41:49 498

原创 Partition List

Problem:Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x.You should preserve the original relative order of the no

2014-10-02 23:40:57 285

原创 Maximal Rectangle

Problem:Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and return its area.数组heits记录同一行中'1'的高度。如果'1'增长,就把行号压栈,因为面积在增大;如果'1'缩短,就把行号退栈,在面积

2014-10-02 23:40:10 322

原创 Largest Rectangle in Histogram

Problem:Given n non-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangle in the histogram.Above is a histogram w

2014-10-02 23:38:36 325

空空如也

空空如也

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

TA关注的人

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