
暑假备战UVa
文章平均质量分 57
每天都要有进步
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
Leetcode#34 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).If the target is not found原创 2015-07-11 16:11:18 · 275 阅读 · 0 评论 -
Leetcode # 103 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 level and alternate between).For example:Given binary原创 2015-08-08 00:21:29 · 241 阅读 · 0 评论 -
Leetcode #107 Binary Tree Level Order Traversal II
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,20,#,#,15,7},原创 2015-08-08 14:45:01 · 294 阅读 · 0 评论 -
Leetcode #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.Difficulty:MediumTreeNode* sortedListToBST(ListNode* head) { TreeNode* root;原创 2015-08-08 16:43:36 · 275 阅读 · 0 评论 -
Leetcode #106 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.Difficulty:Medium/** * Definition for a binary tree原创 2015-08-08 03:42:58 · 252 阅读 · 0 评论 -
Leetcode# 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.Difficulty:MediumTreeNode* build(vector& nums, int start, int end){ int mid = (end+start)/2原创 2015-08-08 16:08:03 · 248 阅读 · 0 评论 -
Leetcode#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原创 2015-08-09 19:58:11 · 246 阅读 · 0 评论 -
Leetcode# 110 Balanced Binary Tree
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 node never diffe原创 2015-08-09 18:18:00 · 238 阅读 · 0 评论 -
Leetcode# 112 Path Sum
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原创 2015-08-09 18:56:02 · 240 阅读 · 0 评论 -
Leetcode #113 Path Sum II
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-08-09 19:10:07 · 284 阅读 · 0 评论 -
Leetcode #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","原创 2015-08-25 05:03:04 · 288 阅读 · 0 评论 -
Leetcode #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.原创 2015-08-11 02:42:06 · 230 阅读 · 0 评论 -
Leetcode# 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 day i.Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, buy on原创 2015-08-11 19:15:09 · 282 阅读 · 0 评论 -
Leetcode #119 Pascal's Triangle II
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?Difficulty:E原创 2015-08-11 02:52:11 · 254 阅读 · 0 评论 -
Leetcode #118 Pascal's Triangle
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]]Difficulty:Easyclass Sol原创 2015-08-11 02:49:41 · 273 阅读 · 0 评论 -
Leetcode #117 Populating Next Right Pointers in Each Node II
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 use constant原创 2015-08-11 02:47:12 · 305 阅读 · 0 评论 -
Leetcode #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], [原创 2015-08-11 17:51:36 · 242 阅读 · 0 评论 -
Leetcode #121 Best Time to Buy and Sell Stock
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 of the stock),原创 2015-08-11 19:14:10 · 284 阅读 · 0 评论 -
Leetcode #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.Difficulty:Easy/** * Definiti原创 2015-08-11 18:09:00 · 250 阅读 · 0 评论 -
Leetcode #136 Single Number
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 e原创 2015-08-09 00:48:03 · 228 阅读 · 0 评论 -
Leetcode #4 Median of Two Sorted Arrays
There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).Difficulty:Hard看似比较简单的一原创 2015-08-13 19:25:54 · 197 阅读 · 0 评论 -
Leetcode #242 Valid Anagram
Given two strings s and t, write a function to determine if t is an anagram of s.For example,s = "anagram", t = "nagaram", return true.s = "rat", t = "car", return false.Note:You may a原创 2015-08-13 15:43:57 · 203 阅读 · 0 评论 -
Leetcode #129 Sum Root to Leaf Numbers
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.Find the tota原创 2015-08-13 01:22:53 · 192 阅读 · 0 评论 -
Leetcode# 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原创 2015-08-13 00:37:51 · 221 阅读 · 0 评论 -
Leetcode #83 Remove Duplicates from Sorted List
Given a sorted linked list, delete all duplicates such that each element appear only once.For example,Given 1->1->2, return 1->2.Given 1->1->2->3->3, return 1->2->3.Difficulty:EasyLi原创 2015-08-02 01:13:17 · 246 阅读 · 0 评论 -
Leetcode#7 Reverse Integer !!!Update (2014-11-10)之后的版本!!!
去年11月份的更新导致优快云博客里老的题解都是错的。其实很简单,用long long 考虑下是否溢出,本人愚笨,用最土的方法,不过至少在两CE,两次WA之后AC了,开森~!题目:Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321原创 2015-06-24 00:49:43 · 208 阅读 · 0 评论 -
Leetcode#21 Merge Two Sorted Lists
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.DIfficulty: easy最近身体精力有限,做题速度放缓了不少。。。ListNode* mergeT原创 2015-07-02 00:56:46 · 257 阅读 · 0 评论 -
Leetcode#15 3Sum
Difficulty:MediumGiven an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note:Element原创 2015-07-05 22:12:19 · 228 阅读 · 0 评论 -
Leetcode#53 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 contiguous subarray [4,−1,2,1] ha原创 2015-07-20 00:48:28 · 188 阅读 · 0 评论 -
Leetcode#35 Search Insert Position
Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You may assume no duplicates in the array.原创 2015-07-11 19:06:15 · 278 阅读 · 0 评论 -
Leetcode #79 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 horizontally or vertically原创 2015-08-01 13:27:27 · 273 阅读 · 0 评论 -
Leetcode# 82 Remove Duplicates from Sorted List II
Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list.For example,Given 1->2->3->3->4->4->5, return 1->2->5.Given 1->1-原创 2015-08-02 00:50:33 · 258 阅读 · 0 评论 -
Leetcode#6 ZigZag Conversion
Difficulty EasyThe 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)原创 2015-06-24 22:13:36 · 285 阅读 · 0 评论 -
Leetcode#19 Remove Nth Node From End of List
Difficulty: easyGiven a linked list, remove the nth node from the end of list and return its head.For example, Given linked list: 1->2->3->4->5, and n = 2. After removing the second原创 2015-06-26 01:28:03 · 270 阅读 · 0 评论 -
Leetcode #28 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 signature of the function had been updat原创 2015-07-08 22:03:10 · 245 阅读 · 0 评论 -
Leetcode #27 Remove Element
Given an array and a value, remove all instances of that value in place and return the new length.The order of elements can be changed. It doesn't matter what you leave beyond the new length.D原创 2015-07-08 21:28:01 · 237 阅读 · 0 评论 -
Leetcode#26 Remove Duplicates from Sorted Array
Difficulty: EasyGiven a sorted array, remove the duplicates in place such that each element appear only once and return the new length.Do not allocate extra space for another array, you must原创 2015-07-06 22:50:00 · 215 阅读 · 0 评论 -
Leetcode # 153 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 contiguous subarray [2,3] has the largest原创 2015-07-20 23:04:54 · 259 阅读 · 0 评论 -
Leetcode #55 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 position.Determine i原创 2015-07-20 21:23:30 · 276 阅读 · 0 评论 -
Leetcode #70 Climbing Stairs
You are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?Difficulty: Easy斐波那契数列。原创 2015-07-21 17:06:37 · 303 阅读 · 0 评论