随笔分类 -  leetcode

Best Time to Buy and Sell Stock系列
摘要: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 阅读全文

posted @ 2014-08-25 15:38 bug睡的略爽 阅读(183) 评论(0) 推荐(0)

Longest Palindromic Substring
摘要:Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longes 阅读全文

posted @ 2014-08-23 20:48 bug睡的略爽 阅读(140) 评论(0) 推荐(0)

Palindrome Partitioning系列
摘要:Palindrome Partitioning Given a string s, partition s such that every substring of the partition is a palindrome. Return all possible palindrome parti 阅读全文

posted @ 2014-08-23 20:27 bug睡的略爽 阅读(164) 评论(0) 推荐(0)

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 t 阅读全文

posted @ 2014-08-22 20:26 bug睡的略爽 阅读(141) 评论(0) 推荐(0)

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 3 阅读全文

posted @ 2014-08-22 16:53 bug睡的略爽 阅读(129) 评论(0) 推荐(0)

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 longes 阅读全文

posted @ 2014-08-22 16:21 bug睡的略爽 阅读(143) 评论(0) 推荐(0)

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 whic 阅读全文

posted @ 2014-08-22 15:55 bug睡的略爽 阅读(112) 评论(0) 推荐(0)

Reverse Integer
摘要:Reverse digits of an integer. Example1: x = 123, return 321Example2: x = -123, return -321 click to show spoilers. Have you thought about this? Here a 阅读全文

posted @ 2014-08-19 23:29 bug睡的略爽 阅读(146) 评论(0) 推荐(0)

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: Pan 阅读全文

posted @ 2014-08-19 23:10 bug睡的略爽 阅读(155) 评论(0) 推荐(0)

Palindrome Number
摘要:Determine whether an integer is a palindrome. Do this without extra space. click to show spoilers. Some hints: Could negative integers be palindromes? 阅读全文

posted @ 2014-08-19 22:54 bug睡的略爽 阅读(126) 评论(0) 推荐(0)

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 cost 阅读全文

posted @ 2014-08-19 20:46 bug睡的略爽 阅读(259) 评论(0) 推荐(0)

Reverse Words in a String
摘要:Given an input string, reverse the string word by word. For example,Given s = "the sky is blue",return "blue is sky the". click to show clarification. 阅读全文

posted @ 2014-08-19 18:26 bug睡的略爽 阅读(151) 评论(0) 推荐(0)

Maximum Subarray
摘要:Maximum Subarray Find the contiguous subarray within an array (containing at least one number) which has the largest sum. For example, given the array 阅读全文

posted @ 2014-08-19 16:17 bug睡的略爽 阅读(414) 评论(0) 推荐(0)

Permutations系列
摘要:一. 全排列递归算法 1. 数据没有重复的情况下 算法:每个元素依次与后面的数进行交换 例子:假设元素为123,则递归交换事例如下: 2. 数据有重复的情况下、 算法:在没有数据重复的全排列下,交换需要加上前提条件,即元素应该和后面没有重复出现的数字进行交换,即当访问到第k个元素的时候,如果 [k, 阅读全文

posted @ 2014-08-16 16:05 bug睡的略爽 阅读(181) 评论(0) 推荐(0)

Sort List系列
摘要:在严老师的数据结构书上学习了各种排序算法,比如插入排序,选择排序,堆排序,快速排序,归并排序等,不过书上代码的应用场景均是底层结构是顺序存储的情况,即数组。 今天总结下对于单链表,常用的排序算法能否使用。由于希尔排序、堆排序、计数排序都要求随机访问,而单链表只能顺序访问,故这 3 种是不能用于单向链 阅读全文

posted @ 2014-08-14 22:20 bug睡的略爽 阅读(225) 评论(0) 推荐(0)

Linked List Cycle系列
摘要:首先讨论下有环单链表相关问题 1. 判断单链表是否有环 使用slow,fast指针从头开始扫描链表,slow指针每次走一步,fast指针每次走两步,如果链表有环,那么fast指针一定会追上slow指针,否则,fast指针会遇到null。 2. 求有环单链表的环长 设环长为R,当fast,slow指针 阅读全文

posted @ 2014-08-14 15:49 bug睡的略爽 阅读(173) 评论(0) 推荐(0)

Construct Binary Tree系列
摘要:Construct Binary Tree from Preorder and Inorder Traversal Given preorder and inorder traversal of a tree, construct the binary tree. Note: You may ass 阅读全文

posted @ 2014-08-12 23:38 bug睡的略爽 阅读(234) 评论(0) 推荐(0)

Binary Tree Level Order Traversal系列
摘要:Binary Tree Level Order Traversal Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level) 阅读全文

posted @ 2014-08-12 22:25 bug睡的略爽 阅读(140) 评论(0) 推荐(0)

Binary Tree Traversal系列
摘要:Binary Tree Preorder Traversal Given a binary tree, return the preorder traversal of its nodes' values. For example: Given binary tree {1,#,2,3}, 1 \ 阅读全文

posted @ 2014-08-12 21:00 bug睡的略爽 阅读(137) 评论(0) 推荐(0)

Single Number 系列
摘要: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 阅读全文

posted @ 2014-08-10 23:49 bug睡的略爽 阅读(156) 评论(0) 推荐(0)

导航