数据结构与算法
文章平均质量分 75
SUN20082567
这个作者很懒,什么都没留下…
展开
-
[LeetCode] - Min Stack O(1)最小栈
Min Stack 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 s原创 2014-11-13 13:34:31 · 1529 阅读 · 0 评论 -
[LeetCode]—Word LadderII 单词递推II
Word Ladder II原创 2014-08-12 14:31:11 · 731 阅读 · 0 评论 -
[九度 1510 剑指offer]—替换空格 数组插入逆向移动
题目:http://ac.jobdu.com/problem.php?pid=1510原创 2014-08-22 16:22:24 · 620 阅读 · 0 评论 -
[九度—剑指offer]—二维数组查找
题目描述:在一个二维数组中,每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序。请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数。输入:输入可能包含多个测试样例,对于每个测试案例,输入的第一行为两个整数m和n(1输入的第二行包括一个整数t(1接下来的m行,每行有n个数,代表题目所给出的m行n列的矩阵(矩阵如题目描述所示,每一原创 2014-08-20 15:27:59 · 711 阅读 · 0 评论 -
[LeetCode]—Permutations II 求全排列(有重复值)
Permutations II Given a collection of numbers that might contain duplicates, return all possible unique permutations.For example,[1,1,2] have the following unique permutations:[1,1,2原创 2014-07-10 11:55:16 · 1029 阅读 · 0 评论 -
[LeetCode]—Subsets 求数组子集
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 subse原创 2014-07-09 16:11:42 · 1131 阅读 · 0 评论 -
[LeetCode]—Next Permutation (全排列字典序)
Next PermutationImplement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possible, it must rea原创 2014-06-16 16:41:11 · 1201 阅读 · 0 评论 -
数据结构与算法[LeetCode]—Permutation Sequence 求n个数的全排列中第K个序列
Permutation Sequence原创 2014-06-18 14:38:26 · 1184 阅读 · 0 评论 -
数据结构与算法[LeetCode]—Binary Tree Level Order Traversal II 从底至上层次输出二叉树每层元素
Binary Tree Level Order Traversal II原创 2014-06-18 16:45:49 · 1271 阅读 · 0 评论 -
[LeetCode]—Subsets II 求数组子集(有重复值)
Subsets II Given a collection of integers that might contain duplicates, S, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set m原创 2014-07-10 09:57:03 · 1231 阅读 · 0 评论 -
[LeetCode]—Word Ladder 单词递推
Word Ladder Given two words (start and end), and a dictionary, find the length of shortest transformation sequence from start to end, such that:Only one letter can be changed at a timeEa原创 2014-07-10 16:28:51 · 831 阅读 · 0 评论 -
[LeetCode]—Permutations 求全排列
Permutations Given a collection of numbers, return all possible permutations.For example,[1,2,3] have the following permutations:[1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], and [3原创 2014-07-10 10:59:28 · 696 阅读 · 0 评论 -
[LeetCode]—Search for a Range 有序数组查找target的下标范围
Search for a Range原创 2014-07-09 09:12:35 · 1005 阅读 · 0 评论 -
数据结构和算法—如何快速求组两个数组的交集
如何快速求两个数组的交集?思路一:原创 2014-06-17 13:10:41 · 3311 阅读 · 0 评论 -
[LeetCode]—Largest Rectangle in Histogram 求直方图最大填充矩形面积
Largest Rectangle in Histogram原创 2014-07-08 16:44:51 · 818 阅读 · 0 评论 -
[LeetCode]—Palindrome Partitioning II 回文分割,求最小分割数
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.原创 2014-08-13 14:38:48 · 1079 阅读 · 0 评论 -
[LeetCode]-Unique PathsII 有障碍的矩阵中求两点间所有路线条数
Unique Paths II原创 2014-08-13 19:21:05 · 1310 阅读 · 0 评论 -
[LeetCode]-Palindrome Partitioning 求回文分割的所有情况
Palindrome Partitioning原创 2014-08-13 11:20:11 · 648 阅读 · 0 评论 -
[LeetCode]-Triangle 求三角形中从顶到底最短距离
Triangle原创 2014-08-30 21:28:33 · 1057 阅读 · 0 评论 -
[九度1512 剑指offer7] 用两个栈实现队列
题目1512:用两个栈实现队列题目描述:用两个栈来实现一个队列,完成队列的Push和Pop操作。队列中的元素为int类型。输入:每个输入文件包含一个测试样例。对于每个测试样例,第一行输入一个n(1接下来的n行,每行输入一个队列操作:1. PUSH X 向队列中push一个整数x(x>=0)2. POP 从队列中pop一个数。原创 2014-08-31 14:22:20 · 768 阅读 · 0 评论 -
[LeetCode]-Edit Distance 两个字符串之间最小编辑距离
Edit Distance原创 2014-08-30 19:29:52 · 941 阅读 · 0 评论 -
[LeetCode]-Palindrome Number 判断整数回文
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? (ie, -1)If y原创 2014-08-17 15:38:58 · 648 阅读 · 0 评论 -
[LeeCode]-Divide Two Integers 不用乘除的除法运算
Divide Two Integers原创 2014-08-17 14:31:00 · 681 阅读 · 0 评论 -
[LeetCode]-Spiral Matrix I&II 螺旋矩阵
Spiral Matrix Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.For example,Given the following matrix:[ [ 1, 2, 3 ], [ 4, 5,原创 2014-08-17 11:16:15 · 803 阅读 · 0 评论 -
[LeetCode]—Word Search
Word SearchGiven a 2D board and a word, find if the word exists in the grid.The word can be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those原创 2014-08-15 21:58:07 · 601 阅读 · 0 评论 -
[LeetCode]-Pascal's Triangle I&II 杨辉三角问题
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(原创 2014-08-16 15:26:03 · 772 阅读 · 0 评论 -
[LeetCode]-Generate Parentheses N个括号所有的组合数
Generate Parentheses Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is:"((()))", "(()原创 2014-08-15 15:31:32 · 1105 阅读 · 0 评论 -
[LeetCode]-Restore IP Addresses
Restore IP Addresses Given a string containing only digits, restore it by returning all possible valid IP address combinations.For example:Given "25525511135",return ["255.255.11.1原创 2014-08-14 17:08:56 · 525 阅读 · 0 评论 -
数据结构与算法[LeetCode]—N_Queen问题
问题N-QueenThe n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.Given an integer n, return all distinct solutions t原创 2013-11-03 21:31:33 · 1097 阅读 · 0 评论 -
[LeetCode]-Combination Sum I&II 求相加和为target的集合
Combination Sum Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.The same repeated number may be ch原创 2014-08-14 21:41:29 · 540 阅读 · 0 评论 -
[LeetCode]-Letter Combinations of a Phone Number 电话键盘的字符串组合
Letter Combinations of a Phone Number原创 2014-08-15 11:37:28 · 694 阅读 · 0 评论 -
[LeetCode]-Surrounded Regions 找被包围的点
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.Fo原创 2014-08-13 10:17:52 · 881 阅读 · 0 评论 -
[LeetCode]—Search a 2D Matrix 有序二维矩阵中查找目标值
Search a 2D Matrix Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:Integers in each row are sorted from left to ri原创 2014-07-09 11:12:32 · 875 阅读 · 0 评论 -
[LeetCode]—Search Insert Position 有序数组中找目标插入的位置
Search Insert Position Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You may a原创 2014-07-09 11:15:56 · 882 阅读 · 0 评论 -
[LeetCode]—Valid Palindrome 回文判断
Valid Palindrome原创 2014-07-01 22:43:45 · 554 阅读 · 0 评论 -
[LeetCode]—Implement strStr() 寻找子串匹配第一个位置 (KMP)
Implement strStr() Implement strStr().Returns a pointer to the first occurrence of needle in haystack, or null if needle is not part of haystack.分析: bent原创 2014-07-02 16:14:13 · 805 阅读 · 0 评论 -
[LeetCode]—Add Binary 两个字符串二进制相加
Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".原创 2014-07-02 20:28:14 · 1899 阅读 · 0 评论 -
数据结构与算法[LeetCode]—TwoSum
Two SumGiven 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 t原创 2014-06-16 19:20:51 · 658 阅读 · 0 评论 -
数据结构与算法[LeetCode]—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?解决思路:使用快慢指针,一个步长为2,一个步长为1,如果快指针遇到NULL,则链表没有环。如果两指原创 2013-11-12 16:17:12 · 1194 阅读 · 0 评论 -
数据结构与算法[LeetCode]—3Sum 求数组中和为0 的三个数的组合
Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note:Elements in a triplet (a,b,c原创 2014-06-25 21:16:08 · 1533 阅读 · 0 评论