自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 134. Gas Station

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

2016-12-30 15:37:30 299

原创 136. Single Number&137. Single Number II

Given an array of integers, every element appears twice except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without using extra

2016-12-30 15:35:56 269

原创 131. Palindrome Partitioning

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[ ["aa","b"], [

2016-12-28 10:17:33 169

原创 125. Valid Palindrome

Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example,"A man, a plan, a canal: Panama" is a palindrome."race a car" is not a pa

2016-12-22 11:38:27 173

原创 127. Word Ladder

Given two words (beginWord and endWord), and a dictionary's word list, find the length of shortest transformation sequence frombeginWord to endWord, such that:Only one letter can be changed at a

2016-12-22 11:37:10 174

原创 121. Best Time to Buy and Sell Stock& 122. Best Time to Buy and Sell Stock II

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

2016-12-21 22:03:33 225

原创 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], [6,

2016-12-18 19:48:53 167

原创 114. 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 6The flattened tree should look like: 1 \

2016-12-14 10:07:39 140

原创 116. Populating Next Right Pointers in Each Node

Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each next pointer to point to its next right node. If the

2016-12-14 10:03:05 142

原创 112. Path Sum&113. Path Sum II

Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.For example:Given the below binary tree and sum =

2016-12-13 14:05:45 157

原创 111. Minimum Depth of Binary Tree

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.一开始想用迭代,但是这题其实用层序遍历比迭代快很多,层序遍历一旦遍历到叶子节

2016-12-13 13:55:22 136

原创 109. Convert Sorted List to Binary Search Tree

Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.这题和数组的区别在于节点值存储在链表里,因此没有办法像数组那样按下标取值。可以每次用两个指针,一个指针一次移动两步,一个一次移动一步,这样的话等移动快的那个指针完成移动后,慢

2016-12-13 13:52:52 163

原创 107. Binary Tree Level Order Traversal II &103. Binary Tree Zigzag Level Order Traversal

107. 就是在正常的层序遍历基础上reverse/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), ri

2016-12-10 10:58:45 155

原创 94. Binary Tree Inorder Traversal&144. Binary Tree Preorder Traversal&145. Binary Tree Postorder Tra

二叉树的前中后序遍历。前序:读取根节点的值并压栈,一直向左找到最左的节点后返回上一层开始向右寻找。中序:将根节点一直压栈并向左寻找,找到最左的节点后读取该节点的值并返回上一层开始向右寻找。这两个其实就是读取值的时间有点不一样而已。后序:后序麻烦一点,输出顺序是左右中,可以通过变量记录当前节点的子树是否已经输出过,一个技巧性的方法是可以设置一个变量记录之前被输出的结点,利用后序遍历父

2016-12-09 10:00:22 186

原创 90. Subsets II

Given a collection of integers that might contain duplicates, nums, return all possible subsets.Note: The solution set must not contain duplicate subsets.For example,If nums = [1,2,2], a solutio

2016-12-06 10:09:35 169

原创 89. Gray Code

he gray code is a binary numeral system where two successive values differ in only one bit.Given a non-negative integer n representing the total number of bits in the code, print the sequence of gra

2016-12-06 10:02:14 155

原创 108. Convert Sorted Array to Binary Search Tree

Given an array where elements are sorted in ascending order, convert it to a height balanced BST.这道题可以用helper也可以不用helper,但是不用helper的话每次都要重新分配数组空间,太浪费。自己的问题主要在递归调用的时候begin和end赋值的问题,一般来说如果在左面的话,end赋

2016-12-05 16:26:15 120

原创 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 keys less than the node's key.The

2016-12-05 16:11:12 144

原创 96. Unique Binary Search Trees

Given n, how many structurally unique BST's (binary search trees) that store values 1...n?For example,Given n = 3, there are a total of 5 unique BST's. 1 3 3 2 1 \

2016-12-04 10:44:10 131

原创 33. Search in Rotated Sorted Array&81. Search in Rotated Sorted Array II

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 to search. If found in the array return its

2016-12-02 10:51:30 154

原创 88. Merge Sorted Array

Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.Note:You may assume that nums1 has enough space (size that is greater or equal to m + n) to hold addit

2016-12-01 10:15:58 125

空空如也

空空如也

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

TA关注的人

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