自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 House Robber II

House Robber II Note: This is an extension of House Robber. After robbing those houses on that street, the thief has found himself a new place for his thievery so that he will not ge

2015-06-30 04:30:17 203

原创 House Robber

House Robber  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 you from robbing each o

2015-06-30 04:10:55 217

原创 summary ranges

Summary Ranges Given a sorted integer array without duplicates, return the summary of its ranges. For example, given [0,1,2,4,5,7], return ["0->2","4->5","7"]. Credits: Special thanks to @

2015-06-30 03:56:51 289

原创 Jump Game

Jump Game 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

2015-06-21 22:42:38 147

原创 Word Search

Word Search 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 horizonta

2015-06-21 22:35:05 211

原创 Maximum Subarray

Maximum Subarray   Find the contiguous subarray within an array (containing at least one number) which has the largest sum. For example, given the array [−2,1,−3,4,−1,2,1,−5,4], the contig

2015-06-21 05:25:26 283

原创 Triangle

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 [

2015-06-21 05:01:54 185

原创 Minimum Size Subarray Sum

Minimum Size Subarray Sum Given an array of n positive integers and a positive integer s, find the minimal length of a subarray of which the sum ≥ s. If there isn't one, return 0 inst

2015-06-21 01:59:41 175

原创 Serialize and Deserialize a binary tree

Serialize and Deserialize a binary tree void Serialize(TreeNode node) { if (node == null) { System.out.print("#" + " "); return; } System.out.print(node.val + " "); Serialize(nod

2015-06-21 00:47:53 207

原创 Ternary Expression

Ternary Expression  a?b:c   a  / \ b   c a?b?c:d:e     a    / \   b   e  / \ c   d a?b:c?d:e    a   / \  b   c     / \    d   e input: String expr output: Expression

2015-06-20 23:48:11 267

原创 Writing a Key Value Store

Writing a Key Value Store The purpose of this exercise is to write a basic key value store. It should use string keys and string values only. The following operations should be supported: set get

2015-06-20 05:19:53 280

原创 Missing Ranges

Missing Ranges Given a sorted integer array where the range of elements are [lower, upper] inclusive, return its missing ranges. For example, given [0, 1, 3, 50, 75], lower = 0 and u

2015-06-19 23:25:25 173

原创 Remove Duplicates from Sorted Array I, II

Remove Duplicates from Sorted Array II 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], You

2015-06-19 06:13:13 255

原创 Best Time to Buy and Sell Stock I, II

Best Time to Buy and Sell Stock I 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 transacti

2015-06-19 05:34:50 278

原创 Course Schedule II

Course Schedule II There are a total of n courses you have to take, labeled from 0 to n - 1. Some courses may have prerequisites, for example to take course 0 you have to first tak

2015-06-19 04:20:06 178

原创 Course Schedule

Course Schedule There are a total of n courses you have to take, labeled from 0 to n - 1. Some courses may have prerequisites, for example to take course 0 you have to first take c

2015-06-19 03:51:20 203

原创 Basic Calculator

Basic Calculator Implement a basic calculator to evaluate a simple expression string. The expression string may contain open ( and closing parentheses ), the plus + or minus sign -

2015-06-18 02:26:09 191

原创 implement a queue using stack

//implement a queue using stack public class Solution { Stack stack1 = new Stack(); Stack stack2 = new Stack(); //pop: dequeue in stack1 public void dequeue() { if (stack1.peek()

2015-06-17 12:34:48 204

原创 implement a stack using queue

Use two queues to implement stack. q2 is used to make sure the new element is always at the front of the q1. public class Solution { Queue q1 = new LinkedList(); Queue q2 = new LinkedList(

2015-06-17 12:25:46 218

原创 Search for a Range

Search for a Range   Given a sorted array of integers, 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).

2015-06-13 08:06:46 185

原创 Search in Rotated Sorted Array

Search in Rotated Sorted Array   Suppose a sorted array 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). You are given a target value

2015-06-13 05:00:52 165

原创 plus one

Plus One 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.

2015-06-09 22:52:24 163

原创 LRU Cache

LRU Cache Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and set. get(key) - Get the value (will always be

2015-06-09 09:58:23 176

原创 Maximal Square

Maximal Square   Given a 2D binary matrix filled with 0's and 1's, find the largest square containing all 1's and return its area. For example, given the following matrix: 1 0 1 0 0 1 0 1 1

2015-06-08 00:10:11 176

原创 Binary Tree Maximum Path Sum

Binary Tree Maximum Path Sum   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

2015-06-07 23:02:06 199

原创 Populating Next Right Pointers in Each Node I, II

Populating Next Right Pointers in Each Node Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; } P

2015-06-07 22:42:01 192

原创 Validate Binary Search Tree

Validate Binary Search Tree

2015-06-07 12:41:42 221

原创 Count Complete Tree Nodes

Count Complete Tree Nodes Given a complete binary tree, count the number of nodes. Definition of a complete binary tree from Wikipedia: In a complete binary tree every level, except possibly

2015-06-07 11:50:19 276

原创 Binary Tree Right Side View

Binary Tree Right Side View Given a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom. For example: Given t

2015-06-07 10:30:24 163

原创 Binary Tree Upside Down

Binary Tree Upside Down Given a binary tree where all the right nodes are either leaf nodes with a sibling (a left node that shares the same parent node) or empty, flip it upside down a

2015-06-06 22:44:30 224

原创 Binary Tree Zigzag Level Order Traversal

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 leve

2015-06-06 22:26:15 170

原创 Convert Sorted Array to Binary Search Tree

Convert Sorted Array to Binary Search Tree Given an array where elements are sorted in ascending order, convert it to a height balanced BST. Using binary search to solve th

2015-06-06 22:23:12 170

转载 sliding window

A long array A[] is given to you. There is a sliding window of size w which is moving from the very left of the array to the very right. You can only see the w numbers in the window. Each time the

2015-06-05 06:14:50 285

原创 Maximum Product Subarray

Maximum Product Subarray   Find the contiguous subarray within an array (containing at least one number) which has the largest product. For example, given the array [2,3,-2,4], the contiguou

2015-06-05 02:25:45 176

原创 Find k most repeating elements

Given a list and a number k, print out the top k most repeating elements in the list. 1. Use hashmap to store the pair of number and count. 2. Use priority queue to store the hash node based on

2015-06-05 02:15:25 251

原创 Implement strStr()

Implement strStr() Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack. Update (2014-11-02): The signatur

2015-06-04 21:55:47 186

原创 Construct Binary Tree from Inorder and Postorder Traversal

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

2015-06-04 06:46:07 180

原创 Construct Binary Tree from Preorder and Inorder Traversal

Construct Binary Tree from Preorder and Inorder Traversal Given preorder and inorder traversal of a tree, construct the binary tree. Note: You may assume that duplicates do not exist in t

2015-06-04 05:50:10 273

原创 Flatten Binary Tree to Linked List

Flatten Binary Tree to Linked List Given a binary tree, flatten it to a linked list in-place. For example, Given 1 / \ 2 5 / \ \ 3 4 6 Th

2015-06-04 05:34:08 186

原创 preorder, inorder, postorder traversal

preorder, inorder, postorder traversal Given a binary tree, return the preorder traversal of its nodes' values. For example: Given binary tree {1,#,2,3}, 1 \ 2 / 3

2015-06-04 05:21:20 257

空空如也

空空如也

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

TA关注的人

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