自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 leetcode #165 in cpp

Compare two version numbers version1 and version2.If version1 > version2 return 1, if version1 version2 return -1, otherwise return 0.You may assume that the version strings are non-empty and co

2016-07-01 11:23:29 240

原创 *leetcode #162 in cpp

A peak element is an element that is greater than its neighbors.Given an input array where num[i] ≠ num[i+1], find a peak element and return its index.The array may contain multiple peaks, in

2016-06-30 11:15:21 237

原创 leetcode #160 in cpp

Write a program to find the node at which the intersection of two singly linked lists begins.For example, the following two linked lists:A: a1 → a2 ↘

2016-06-30 10:33:43 368

原创 leetcode #155 in cpp

Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.push(x) -- Push element x onto stack.pop() -- Removes the element on top of the stack.top() -- Get

2016-06-29 11:54:16 205

原创 leetcode #154 in cpp

Follow up for "Find Minimum in Rotated Sorted Array":What if duplicates are allowed?Would this affect the run-time complexity? How and why?Suppose a sorted array is rotated at some pivot u

2016-06-29 11:35:02 210

原创 leetcode #153 in cpp

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).Find the minimum element.You may assume no duplicate exists in

2016-06-29 11:04:00 179

原创 leetcode #153 in cpp

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).Find the minimum element.You may assume no duplicate exists in

2016-06-29 11:00:13 191

原创 leetcode #152 in cpp

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

2016-06-29 10:47:58 182

原创 leetcode #151 in cpp

Solution:1. reversed the whole string2. reversed each word in the reversed string.3. remove multiple space between words. Code:class Solution {public: void reverseWords(string &s) {

2016-06-29 10:28:55 176

原创 leetcode #150 in cpp

Evaluate the value of an arithmetic expression in Reverse Polish Notation.Valid operators are +, -, *, /. Each operand may be an integer or another expression.Some examples: ["2", "1",

2016-06-28 11:15:17 204

原创 leetcode #149 in cpp

Given n points on a 2D plane, find the maximum number of points that lie on the same straight line.Solution:  three points,p1,p2,p3, are on the same line if and only if slope(p2) == slope(p3)

2016-06-28 10:59:58 192

原创 leetcode #145 in cpp

Solution:The post-order is the reverse of the root->right->left order. The root->right->left order is similar to pre-order traversal. Thus we first do a pseudo-pre-order traversal, by collecting roo

2016-06-26 12:06:47 226

原创 leetcode #144 in cpp

Given a binary tree, return the preorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [1,2,3].Note: Recursive soluti

2016-06-26 11:52:14 202

原创 Leetcode #143 in cpp

Given a singly linked list L: L0→L1→…→Ln-1→Ln,reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→…You must do this in-place without altering the nodes' values.For example,Given {1,2,3,4}, reorder it to 

2016-06-26 06:31:59 182

原创 #leetcode #142 in cpp

Given a linked list, return the node where the cycle begins. If there is no cycle, return null.Note: Do not modify the linked list.Follow up:Can you solve it without using extra space?So

2016-06-26 05:46:02 175

原创 leetcode #141 in cpp

Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?Solution;Make a slow pointer which step 1 in each iteration and a fast pointer

2016-06-25 12:01:24 171

原创 leetcode #140 in cpp

Code:class Solution {public: vector wordBreak(string s, unordered_set& wordDict) { vector res; if(s.empty()) return res; int n = s.length(); vector> prev(n,ve

2016-06-25 11:56:39 155

原创 leetcode #139 in cpp

Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separated sequence of one or more dictionary words.For example, givens = "leetcode",dict = ["leet"

2016-06-25 11:08:21 176

原创 *leetcode 138 in cpp

A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null.Return a deep copy of the list.The problem is to maintain the

2016-06-24 11:28:47 337

原创 *leetcode #136 in cpp

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 ext

2016-06-22 12:38:15 192

原创 *leetcode #135 in cpp

There are N 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 least on

2016-06-22 12:27:27 184

原创 *leetcode #134 in cpp

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 travel from station i to

2016-06-22 11:49:04 150

原创 *leetcode #132 in cpp

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 = "aab",Return

2016-06-22 04:14:48 120

原创 leetcode #131 in cpp

Solution:We have already done in #4 about how to find palindrome in a string. Given isPal[i][j] which represents whether s[i...j] is palindrome, we could scan through the array to find the first pal

2016-06-21 04:28:09 177

原创 leetcode #4 in cpp

Code:class Solution {public: string longestPalindrome(string s) { int n = s.length(); bool dp[n][n] = {false}; int maxx = 1; int begin = 0; int end =

2016-06-21 04:03:40 122

原创 leetcode #130 in cpp

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 X XX O O X

2016-06-21 02:28:15 164

原创 leetcode #129 in cpp

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

2016-06-20 13:28:25 121

原创 *leetcode #128 in cpp

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 sequence is [1, 2, 3

2016-06-20 13:17:35 196

原创 leetcode #127 in cpp

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

2016-06-20 12:32:56 153

原创 leetcode #125 in cpp

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

2016-06-20 05:01:29 172

原创 *leetcode #124 in cpp

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. The

2016-06-20 04:45:58 141

原创 *leetcode #123 in cpp

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.Note:You may

2016-06-20 02:54:52 218

原创 leetcode #122 in cpp

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

2016-06-19 07:13:50 188

原创 leetcode #121 in cpp

Solution:We should look for increasing order in the list. Suppose we have an increasing list, then the maximum profit is the list end - list start in this list. Suppose we have the increasing list

2016-06-19 06:57:19 135

原创 leetcode #119 in cpp

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?Code:class S

2016-06-19 06:06:27 151

原创 leetcode #118 in cpp

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]]Code:class Solution {p

2016-06-19 05:57:18 147

原创 leetcode #117 in cpp

Solution:Similar to #116. Only difference is that we push left or right into queue when left/right is not NULL.Code:/** * Definition for binary tree with next pointer. * struct TreeLinkNode {

2016-06-19 05:41:33 185

原创 leetcode #116 in cpp

Solution:perform BFS to traverse the tree level by level using a queue. For each level, pop current front node,  link the node's next to the new front node in the queue.Code:/** * Definition fo

2016-06-19 05:31:23 178

原创 *leetcode #115 in cpp

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 some (can be non

2016-06-19 05:19:34 151

原创 leetcode #114 in cpp

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-06-18 22:12:58 273

空空如也

空空如也

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

TA关注的人

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