
leetCode算法
文章平均质量分 67
momentforver
这个作者很懒,什么都没留下…
展开
-
leetcode之Interleaving String
原题如下:Given 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.When s3 = "aadbb原创 2014-10-18 22:40:55 · 373 阅读 · 0 评论 -
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原创 2014-05-23 15:36:01 · 309 阅读 · 0 评论 -
leetcode之Merge Intervals
原题如下:Given a collection of intervals, merge all overlapping intervals.For example,Given [1,3],[2,6],[8,10],[15,18],return [1,6],[8,10],[15,18].关键还是思路,当理解了原创 2014-06-07 21:46:26 · 358 阅读 · 0 评论 -
leetcode之Reorder List
原题如下: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}, reo原创 2014-06-08 21:09:44 · 349 阅读 · 0 评论 -
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原创 2014-04-25 15:40:23 · 454 阅读 · 0 评论 -
Reverse Linked List II
原题如下:Reverse a linked list from position m to n. Do it in-place and in one-pass.For example:Given 1->2->3->4->5->NULL, m = 2 and n = 4,return 1->4->3->2->5->NULL.Note:Given m,原创 2014-05-07 17:20:33 · 297 阅读 · 0 评论 -
leetcode之Recover Binary Search Tree
原题如下:Two elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure.Note:A solution using O(n) space is pretty straight forward. Coul原创 2014-05-20 21:24:47 · 397 阅读 · 0 评论 -
leetcode之Best Time to Buy and Sell Stock && II && III
Best Time to Buy and Sell Stock的原题如下:原创 2014-05-22 23:11:01 · 425 阅读 · 0 评论 -
leetcode之Jump Game && Jump Game II
Jump Game的原题如下:Given 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 pos原创 2014-05-19 16:29:54 · 371 阅读 · 0 评论 -
leetcode之 Longest Substring Without Repeating Characters
这道题的暴力解法比较简单,原创 2014-05-21 22:53:23 · 438 阅读 · 0 评论 -
leetcode之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-05-14 16:14:12 · 227 阅读 · 0 评论 -
leetcode之Implement strStr()
Implement strStr().Returns a pointer to the first occurrence of needle in haystack, or null if needle is not part of haystack.原创 2014-06-03 19:23:52 · 406 阅读 · 0 评论 -
leetcode之Maximal Rectangle
原题如下:Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and return its area.此题s原创 2014-06-02 17:08:40 · 520 阅读 · 0 评论 -
leetcode之Add Two Numbers
原题如下:You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return i原创 2014-05-20 22:59:25 · 275 阅读 · 0 评论 -
leetcode之Anagrams
原题如下:Given an array of strings, return all groups of strings that are anagrams.不得不说,这道题的题意太模糊了,原创 2014-05-20 17:01:04 · 463 阅读 · 0 评论 -
leetcode之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 N原创 2014-05-20 15:56:03 · 368 阅读 · 0 评论 -
leetcode之Reverse Nodes in k-Group
原题如下:Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.If the number of nodes is not a multiple of k then left-out nodes in the end should rema原创 2014-05-12 19:54:03 · 268 阅读 · 0 评论 -
leetcode之Merge k Sorted Lists
原题如下:Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.思路一:按照归并排序的思路原创 2014-05-19 21:34:31 · 328 阅读 · 0 评论 -
leetcode之Sort List
原题如下:Sort a linked list in O(n log n) time using constant space complexity.leetcode上原创 2014-06-08 11:49:57 · 349 阅读 · 0 评论 -
leetcode之Scramble String
原题如下:Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively.Below is one possible representation of s1 = "great": great /原创 2014-05-25 22:55:42 · 411 阅读 · 0 评论 -
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.思路:原创 2014-04-14 19:15:28 · 310 阅读 · 0 评论 -
leetcode之Subsets
原题如下:Given a set of distinct integers, S, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set must not contain duplicate subsets.原创 2014-04-21 20:22:58 · 303 阅读 · 0 评论 -
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.原创 2014-05-22 15:54:10 · 347 阅读 · 0 评论 -
leetcode之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".这道题的题意很明确,首先想到的是将字符串按空格分割原创 2014-06-07 22:49:49 · 354 阅读 · 0 评论 -
leetcode之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",dic原创 2014-06-03 22:28:24 · 399 阅读 · 0 评论 -
leetcode之Permutation Sequence
原题如下:The set [1,2,3,…,n] contains a total of n! unique permutations.By listing and labeling all of the permutations in order,We get the following sequence (ie, for n = 3):"123""132""原创 2014-06-03 09:40:03 · 400 阅读 · 0 评论 -
leetcode之Largest Rectangle in Histogram
原题如下:Given n non-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangle in the histogram.Above is a histogram wh原创 2014-05-30 11:41:55 · 620 阅读 · 0 评论 -
leetcode之Roman to Integer && Integer to Roman
Roman to Integer 的原题如下:原创 2014-05-28 20:44:32 · 534 阅读 · 0 评论 -
leetcode之Median of Two Sorted Arrays
原题如下:There are two sorted arrays A and B of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).这道题muqian原创 2014-06-10 09:56:03 · 562 阅读 · 0 评论 -
leetcode之3Sum
原题如下:原创 2014-06-11 15:15:28 · 506 阅读 · 0 评论 -
leetcode之Clone Graph
原题如下:Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors.OJ's undirected graph serialization:Nodes are labeled uniquely.We use # as a separ原创 2014-05-28 17:09:24 · 570 阅读 · 0 评论 -
leetcode之Sqrt(x)
原题如下:Implement int sqrt(int x).Compute and return the square root of x.普通遍历方法kendi原创 2014-05-27 16:33:40 · 360 阅读 · 0 评论 -
leetcode之Two Sum
原题如下:Given an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers such that they add up to the原创 2014-06-10 10:43:24 · 360 阅读 · 0 评论 -
leetcode之First Missing Positive
原题如下:Given an unsorted integer array, find the first missing positive integer.For example,Given [1,2,0] return 3,and [3,4,-1,1] return 2.Your algorithm should run in O(n) time and us原创 2014-05-26 21:05:51 · 385 阅读 · 0 评论 -
leetcode之Rotate List
原题如下:Given 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-05-27 14:53:14 · 356 阅读 · 0 评论 -
leetcode之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:原创 2014-06-09 21:32:33 · 287 阅读 · 0 评论 -
leetcode之Trapping Rain Water
有一周没更新博客了,过去的一周打击太大原创 2014-04-20 09:19:37 · 300 阅读 · 0 评论 -
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原创 2014-05-19 16:45:44 · 376 阅读 · 0 评论 -
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.之前有一个将顺序存储的vectorbianhuan原创 2014-04-26 21:55:43 · 400 阅读 · 0 评论 -
leetcode之4Sum
紧接上篇的3Sun问题,4Sum问题的描述如下:Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of原创 2014-04-26 16:49:24 · 262 阅读 · 0 评论