Leetcode
文章平均质量分 69
水晶莲
这个作者很懒,什么都没留下…
展开
-
Binary Tree Zigzag Level Order Traversal
Binary Tree Zigzag Level Order TraversalGiven 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 leve原创 2014-09-03 14:19:15 · 295 阅读 · 0 评论 -
Word Break
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"原创 2014-08-17 13:07:03 · 249 阅读 · 0 评论 -
Minimum Path Sum
Minimum Path SumGiven a m x n grid filled with non-negative numbers, find a path from top left to bottom right whichminimizes the sum of all numbers along its path.Note: You can on原创 2014-08-29 11:01:27 · 294 阅读 · 0 评论 -
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 / \原创 2014-08-16 19:24:05 · 295 阅读 · 0 评论 -
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 usi原创 2014-08-17 11:17:46 · 362 阅读 · 0 评论 -
Jump Game
Jump GameGiven 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原创 2014-08-17 10:26:35 · 289 阅读 · 0 评论 -
Single Number
Single NumberGiven 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 i原创 2014-08-17 11:16:43 · 304 阅读 · 0 评论 -
Jump Game II
Jump Game II原创 2014-08-17 10:27:46 · 322 阅读 · 0 评论 -
Simplify Path
Given an absolute path for a file (Unix-style), simplify it.For example,path = "/home/", => "/home"path = "/a/./b/../../c/", => "/c"click to show corner cases.Corner Cases:Did原创 2014-08-16 11:51:49 · 232 阅读 · 0 评论 -
Generate Parentheses
Generate Parentheses Total Accepted: 17229 Total Submissions: 54927My SubmissionsGiven n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.原创 2014-08-13 14:05:07 · 363 阅读 · 0 评论 -
Edit Distance
Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.)You have the following 3 operations permitted on a word:原创 2014-08-16 10:25:54 · 284 阅读 · 0 评论 -
Count and Say
Count and SayThe count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...1 is read off as "one 1" or 11.11 is read off as "two 1s" or 21.原创 2014-08-31 09:13:36 · 361 阅读 · 0 评论 -
Insert Interval
Insert IntervalGiven a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary).You may assume that the intervals were initially sorted accor转载 2014-08-30 11:20:14 · 322 阅读 · 0 评论 -
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.原创 2014-09-03 13:54:43 · 299 阅读 · 0 评论 -
Rotate List
Rotate ListGiven a list, rotate the list to the right by k places, where k is non-negative.For example:Given 1->2->3->4->5->NULL and k = 2,return 4->5->1->2->3->NULL.原创 2014-09-01 16:06:35 · 370 阅读 · 0 评论 -
Remove Nth Node From End of List
Remove Nth Node From End of ListGiven 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.原创 2014-09-01 10:26:02 · 310 阅读 · 0 评论 -
Plus One
Plus OneGiven 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.ve转载 2014-09-01 10:09:40 · 330 阅读 · 0 评论 -
Search for a Range
Search for a RangeGiven 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原创 2014-09-01 14:48:24 · 341 阅读 · 0 评论 -
Palindrome Partitioning II
Palindrome Partitioning IIGiven 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.原创 2014-08-18 11:59:13 · 259 阅读 · 0 评论 -
Interleaving String
Interleaving StringGiven s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2.For example,Given:s1 = "aabcc",s2 = "dbbca",When s3 = "aadbbcbcac", return true.原创 2014-08-30 15:00:37 · 299 阅读 · 0 评论 -
Triangle
TriangleGiven 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],原创 2014-08-18 09:37:04 · 261 阅读 · 0 评论 -
Populating Next Right Pointers in Each Node
Populating Next Right Pointers in Each Node void connect(TreeLinkNode *root) { if(root==NULL||root->left ==NULL) return; else { root->left->原创 2014-08-17 20:16:48 · 342 阅读 · 0 评论 -
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原创 2014-08-16 15:48:27 · 270 阅读 · 0 评论 -
Partition List
Partition ListGiven 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 ord转载 2014-08-27 15:52:58 · 305 阅读 · 0 评论 -
LRU Cache
LRU CacheDesign and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and set.get(key) - Get the value (will always be转载 2014-08-27 15:03:03 · 316 阅读 · 0 评论 -
Longest Substring Without Repeating Characters
Longest Substring Without Repeating Characters Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating l转载 2014-08-10 14:40:30 · 348 阅读 · 0 评论 -
ZigZag Conversion
The 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)P A H NA P L S转载 2014-08-11 09:46:29 · 313 阅读 · 0 评论 -
Reverse Linked List II
Reverse Linked List II原创 2014-09-05 16:20:28 · 318 阅读 · 0 评论 -
Candy
CandyThere 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转载 2014-09-04 15:39:50 · 305 阅读 · 0 评论 -
Balanced Binary Tree
Balanced Binary TreeGiven 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 tw转载 2014-08-20 16:02:25 · 428 阅读 · 0 评论 -
Pascal's Triangle
Pascal's Triangle原创 2014-08-20 13:34:40 · 301 阅读 · 0 评论 -
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),原创 2014-08-20 11:20:18 · 378 阅读 · 0 评论 -
Subsets (II)
Subsets II原创 2014-08-18 14:16:33 · 256 阅读 · 0 评论 -
求解最长不重复子序列(后缀数组)
#include "iostream"#include "string"using namespace std;#define MAXLEN 10000char a[MAXLEN],*suff[MAXLEN];int comlen(char* p,char* q){int maxlen =0;while((*p)&&(*q)&&(*p==*q)){m原创 2014-04-18 09:29:48 · 669 阅读 · 0 评论 -
Validate Binary Search Tree
Validate Binary Search TreeGiven 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转载 2014-09-07 09:50:30 · 356 阅读 · 0 评论 -
字符串转化成整形
#include "iostream"#include "string"using namespace std;int aToi(const char *str){ bool flag =false; if (!str) { return 0; } int k=0; if (!strlen(str)) { return 0; } while(str[k] ==原创 2014-08-11 14:02:03 · 636 阅读 · 0 评论 -
Convert Sorted List to Binary Search Tree
Convert Sorted List to Binary Search TreeGiven a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.转载 2014-08-24 11:05:52 · 401 阅读 · 0 评论 -
Climbing Stairs
class Solution {public: int climbStairs(int n) { if(n <= 2) { return n; } else { int* step = new int[n]; step[0] = 1; step[1] = 2; for(int i = 2; i原创 2014-08-14 18:54:03 · 273 阅读 · 0 评论 -
Evaluate Reverse Polish Notation
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",原创 2014-08-14 19:53:14 · 275 阅读 · 0 评论 -
Linked List Cycle
Linked List CycleGiven a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?转载 2014-08-25 10:45:39 · 291 阅读 · 0 评论