自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

  • 博客(153)
  • 收藏
  • 关注

原创 [LeetCode] Word BreakII

Given a string s and a dictionary of words dict, add spaces ins to construct a sentence where each word is a valid dictionary word.Return all such possible sentences.For example, givens = "cat

2013-10-21 11:35:46 325

原创 [LeetCode] Word Break

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

2013-10-21 11:34:32 317

原创 [LeetCode] Copy List with Random Pointer

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. 该题与clone graph类似,使用一个map保存原链表中的映射

2013-10-21 11:31:51 279

原创 [LeetCode] Single Number II

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

2013-10-21 11:30:12 846

原创 [LeetCode] 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 extra

2013-10-21 11:29:13 215

原创 [LeetCode] Candy

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

2013-10-21 11:28:10 304

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

2013-10-21 11:24:25 334

原创 [LeetCode] Clone Graph

Clone an undirected graph. Each node in the graph contains a label and a list of itsneighbors.OJ's undirected graph serialization:Nodes are labeled uniquely.We use # as a separator for each

2013-10-21 11:16:52 285

原创 [LeetCode] Palindrome Partitioning II

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 1 s

2013-10-21 11:06:48 262

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

2013-10-21 11:03:22 280

原创 [LeetCode] Surrounded Regions

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

2013-10-21 10:59:12 257

原创 [LeetCode] 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 number123.Find the total sum

2013-10-21 10:34:08 242

原创 [LeetCode] Longest Consecutive Sequence

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,

2013-10-21 10:31:20 231

原创 [LeetCode] Word Ladder II

Given two words (start and end), and a dictionary, find all shortest transformation sequence(s) fromstart to end, such that:Only one letter can be changed at a timeEach intermediate word must ex

2013-10-21 10:26:08 280

原创 [LeetCode] Word Ladder

Word LadderAC Rate: 1100/7336My SubmissionsGiven two words (start and end), and a dictionary, find the length of shortest transformation sequence fromstart to end, such that: Onl

2013-10-19 21:19:09 276

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

2013-10-19 21:02:31 237

原创 [LeetCode] 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 / \ 2 3Return 6.  

2013-10-19 20:59:09 254

原创 [LeetCode] Best Time to Buy and Sell Stock III

Say you have an array for which the ith element is the price of a given stock on dayi.Design an algorithm to find the maximum profit. You may complete at most two transactions.Note:You may not

2013-10-19 20:45:53 345

原创 [LeetCode] 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.Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, buy one

2013-10-19 20:21:47 358

原创 [LeetCode] 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 dayi.If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the stock),

2013-10-19 20:16:32 387

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

2013-10-19 20:14:10 224

原创 [LeetCode] 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 the tree.中序和前序 或者中序和后驱可以唯一确定一颗二叉树/** * Definition for binary tr

2013-10-19 20:10:01 363

原创 [LeetCode] 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?求杨辉三角形的第i行,与上一题一样,

2013-10-18 11:49:41 209

原创 [LeetCode] 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]]递归公式num[i][j] = num[i-1]

2013-10-18 11:47:51 248

原创 [LeetCode] 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 extr

2013-10-18 11:45:44 201

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

2013-10-18 11:40:57 202

原创 [LeetCode] Distinct Subsequences

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 none)

2013-10-18 11:37:03 212

原创 [LeetCode] 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 \

2013-10-18 11:29:35 284

原创 [LeetCode] Path SumII

Path Sum II AC Rate: 1316/5087My SubmissionsGiven 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 bina

2013-10-18 11:24:07 311

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

2013-10-18 11:21:56 265

原创 [LeetCode] 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.求一颗二叉树的最小高度,/** * Definition fo

2013-10-18 11:20:00 203

原创 [LeetCode] 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 differ

2013-10-18 11:18:44 253

原创 [LeetCode] 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.有序链表转为平衡的二叉搜索树与数组类似,找到链表的中间节点,链表左半部分递归转化,右半部分递归转化/** * Definition for singly-linke

2013-10-18 11:17:31 233

原创 [LeetCode] Convert Sorted Array to Binary Search Tree

Given an array where elements are sorted in ascending order, convert it to a height balanced BST.从有序数组构造二叉搜索树二叉搜索树要是平衡的,因此每次以数组中间元素作为跟,然后数组左半部分元素作为左子树递归,右半部分作为右子树递归递归即简洁/** * Defini

2013-10-18 11:15:52 307

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

2013-10-18 11:13:21 192

原创 [LeetCode] 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./** * Definition for binary tree * struct TreeNode

2013-10-18 11:11:34 405

原创 [leetcode]二叉树总结

1. 二叉树的前序遍历Sum Root to Leaf Numbers: 在前序遍历过程中,对于当前结点,记录从根结点到当前结点组成的数字。当当前结点为叶节点时,将这个数字加到sum上。

2013-10-18 10:47:40 548

原创 [leetcode]数组总结

1. 找递增或递减序列while(endratings[end-1]){ candies[end] = candies[end-1] + 1; end++;}2. 加油站问题n个加油站,组成一圈,每个点有加油g[i],每两个点之间耗油c[i]。判断能不能从一个点出发绕一圈?只要g[i]之和大于等于c[i]之和即可。找到一个合理的起点。计算v[

2013-10-18 09:48:07 308

原创 [leetcode]回溯总结

回溯的关键点:递归函数的参数设计,递归之前push_back,递归之后pop_back。1) Word Break II首先使用动态规划计算出子串s[i]...s[j]是否能够被分割成多个单词。(见Work Break)然后递归的创建句子。递归函数的参数有当前处理的s的开头下标begin,当前已经选择了的单词的集合temp,最终结果的集合result。当begin到达s的末尾时,说

2013-10-18 09:39:41 528

原创 [leetcode]动态规划总结

1. 两维的动态规划1) Word Break:f[i, j]表示子串s[i]...s[j]是否可以表示成若干单词组成的句子。递推公式:如果存在i初始条件:若f[i,j]就是个单词,则f[i,j]=true。2) Palindrome Partitionf[i,j]表示子串s[i]...s[j]是否可以表示成若干回文的组合。递推公式:如果s[i]=s[j],则f[i,j

2013-10-18 09:39:21 1065

空空如也

空空如也

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

TA关注的人

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