自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 [leetcode] 124. Binary Tree Maximum Path Sum

Given a binary tree, find the maximum path sum.For this problem, a path is defined as any sequence of nodes from some starting node to any node in the tree along the parent-child connections. Th

2015-12-28 16:26:21 414

原创 [leetcode] 322. Coin Change

You are given coins of different denominations and a total amount of moneyamount. Write a function to compute the fewest number of coins that you need to make up that amount. If that amount of mon

2015-12-28 11:33:16 2312

原创 [leetcode] 228. 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"].前几天看到有同学留言了这道题,题目要求把排序好的数组合并成区间,难度为easy。题目

2015-12-22 10:01:54 394

原创 [leetcode] 73. Set Matrix Zeroes

Given am x n matrix, if an element is 0, set its entire row and column to 0. Do it in place.Follow up:Did you use extra space?A straight forward solution using O(mn) space is proba

2015-12-21 16:13:48 419

原创 [leetcode] 129. Sum Root to Leaf Numbers

Given a binary tree containing digits from0-9 only, each root-to-leaf path could represent a number.An example is the root-to-leaf path1->2->3 which represents the number123.Find the t

2015-12-20 21:33:13 322

原创 [leetcode] 88. Merge Sorted Array

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

2015-12-19 20:03:30 291

原创 [leetcode] 319. Bulb Switcher

There aren bulbs that are initially off. You first turn on all the bulbs. Then, you turn off every second bulb. On the third round, you toggle every third bulb (turning on if it's off or turning o

2015-12-19 19:47:18 333

原创 [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.这道题是合并两个已排序链表,题目难度为easy。题目比较简单,注意表头的处理即可。具体代码:class

2015-12-18 18:14:25 360

原创 [leetcode] 92. Reverse Linked List II

Reverse a linked list from positionm to n. Do it in-place and in one-pass.For example:Given1->2->3->4->5->NULL,m = 2 and n = 4,return1->4->3->2->5->NULL.Note:Given

2015-12-18 16:05:26 262

原创 [leetcode] 61. Rotate List

Given a list, rotate the list to the right byk places, where k is non-negative.For example:Given1->2->3->4->5->NULL andk = 2,returnreturn4->5->1->2->3->NULL.这道题是循环右移链表,

2015-12-17 21:39:10 293

原创 [leetcode] 257. Binary Tree Paths

Given a binary tree, return all root-to-leaf paths.For example, given the following binary tree: 1 / \2 3 \ 5All root-to-leaf paths are:["1->2->5", "1->3"]这道题是找出找出二叉树根节

2015-12-17 11:22:10 283

原创 [leetcode] 5. Longest Palindromic Substring

Given a stringS, find the longest palindromic substring inS. You may assume that the maximum length ofS is 1000, and there exists one unique longest palindromic substring.这道题是找出字符串的最长回文子串,题目

2015-12-17 10:19:42 316

原创 [leetcode] 234. Palindrome 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?这道题是判断单链表是否构成回文,题目难度为easy。由于时间复杂度要求O(n),空间复杂度要求O(1),因而不能用栈或递归。我们可以通过快慢

2015-12-16 21:26:10 380

原创 [leetcode] 86. Partition List

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 nodes in each

2015-12-15 16:29:00 322

原创 [leetcode] 238. Product of Array Except Self

Given an array of n integers where n > 1, nums, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i].Solve it without division and in O

2015-12-15 10:08:23 271

原创 [leetcode] 134. 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 costscost[i] of gas to travel from station

2015-12-14 22:02:17 346

原创 [leetcode] 31. Next Permutation

Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possible, it must rearrange it as the lowest possible

2015-12-11 11:21:13 619

原创 [leetcode] 200. Number of Islands

Given a 2d grid map of'1's (land) and '0's (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may a

2015-12-10 16:45:54 362

原创 [leetcode] 237. Delete Node in a Linked List

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 is1 -> 2 -> 3 -> 4 and you are given the third node with va

2015-12-10 10:49:29 260

原创 [leetcode] 213. House Robber II

Note: This is an extension ofHouse Robber.After robbing those houses on that street, the thief has found himself a new place for his thievery so that he will not get too much attention. This t

2015-12-09 18:37:16 504

原创 [leetcode] 198. 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 of them is that adjacent hou

2015-12-09 18:18:38 735

原创 [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-12-09 10:25:13 349

原创 [leetcode] 199. 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 the following binary tree, 1

2015-12-08 21:29:38 278

原创 [leetcode] 66. 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.这道题是计算N+1,N用数组表示,题目难

2015-12-08 16:32:10 287

原创 [leetcode] 222. Count Complete Tree Nodes

Given acompletebinary tree, count the number of nodes.In a complete binary tree every level, except possibly the last, is completely filled, and all nodes in the last level are as far left as

2015-12-08 16:00:31 397

原创 [leetcode] 14. Longest Common Prefix

Write a function to find the longest common prefix string amongst an array of strings.这道题是找出所有字符串的公共前缀,题目难度为easy。题目比较简单就直接上代码了:class Solution {public: string longestCommonPrefix(vector& s

2015-12-07 16:08:43 307

原创 [leetcode] 206. Reverse Linked List

Reverse a singly linked list.Hint:A linked list can be reversed either iteratively or recursively. Could you implement both?这道题是反转链表,题目难度为easy。题目比较简单,需要记录下前一节点以便后续节点修改next,具体代码:class S

2015-12-07 15:54:00 291

原创 [leetcode] 215. Kth Largest Element in an Array

Find thekth 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-12-07 10:29:31 231

原创 [leetcode] 223. Rectangle Area

Find the total area covered by tworectilinear rectangles in a 2D plane.Each rectangle is defined by its bottom left corner and top right corner as shown in the figure.Assume that the t

2015-12-07 09:32:50 298

原创 [leetcode] 103. Binary Tree Zigzag Level Order Traversal

Given a binary tree, return thezigzag 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 bi

2015-12-03 20:24:38 255

原创 [leetcode] 95. Unique Binary Search Trees II

Givenn, generate all structurally unique BST's (binary search trees) that store values 1...n.For example,Given n = 3, your program should return all 5 unique BST's shown below. 1

2015-12-03 16:32:10 371

原创 [leetcode] 226. Invert Binary Tree

Invert a binary tree. 4 / \ 2 7 / \ / \1 3 6 9to 4 / \ 7 2 / \ / \9 6 3 1Trivia:This problem was inspired bythis original tweet byMax Ho

2015-12-03 10:58:18 214

原创 [leetcode] 242. Valid Anagram

Given two stringss 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.Not

2015-12-03 10:11:14 270

原创 [leetcode] 20. Valid Parentheses

Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.The brackets must close in the correct order, "()" and "()[]{}" are all va

2015-12-02 21:02:15 235

原创 [leetcode] 67. Add Binary

Given two binary strings, return their sum (also a binary string).For example,a ="11"b ="1"Return"100".今天的题目是二进制加法,偶尔换个简单的题消遣一下,题目难度为easy。题目本身比较简单,需要从低位进行计算,注意最后的进位就可以了。具体代码:

2015-12-02 17:04:38 336

原创 [leetcode] 135. Candy

There areN children standing in a line. Each child is assigned a rating value.You are giving candies to these children subjected to the following requirements:Each child must have at l

2015-12-02 16:12:11 415

原创 [leetcode] 203. Remove Linked List Elements

Remove all elements from a linked list of integers that have valueval.ExampleGiven: 1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6, val = 6Return: 1 --> 2 --> 3 --> 4 --> 5这道题比较简单,删除链

2015-12-01 19:46:46 256

原创 [leetcode] 279. Perfect Squares

Given a positive integern, find the least number of perfect square numbers (for example, 1, 4, 9, 16, ...) which sum to n.For example, givenn = 12, return3 because12 = 4 + 4 + 4; g

2015-12-01 15:42:32 411

空空如也

空空如也

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

TA关注的人

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