自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

Havenoidea 的专栏

更新ing…… 喜欢就加关注~

  • 博客(51)
  • 资源 (1)
  • 收藏
  • 关注

原创 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",题意把给定的字符串分割,使得每个子串都是回文串,枚举所有的可能情况。

2013-09-30 11:10:32 4609

原创 leetcode:Palindrome Number (判断数字是否回文串) 【面试算法题】

Determine whether an integer is a palindrome. Do this without extra space.题意判断数字是否是回文串,只能用常数空间,不能转换成字符串,不能反转数字。

2013-09-29 22:01:05 10323

原创 leetcode:Next Permutation (求下一个排列) 【面试算法题】

Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possible, it must rearrange it as the lowest possible order (ie, sorted in ascending order).The replacement mus

2013-09-29 21:18:02 11062

原创 leetcode:N-Queens II (n皇后问题2)【面试算法题】

题目:Follow up for N-Queens problem.Now, instead outputting board configurations, return the total number of distinct solutions.题意输出n×n的皇后棋子布局有多少种不同的情况。和上题一样的思路,只是不需要输出图,每次满足条件的时候记录一下次数。

2013-09-29 17:13:18 3395

原创 leetcode:N-Queens (n皇后问题) 【面试算法题】

题目:Given an integer n, return all distinct solutions to the n-queens puzzle.Each solution contains a distinct board configuration of the n-queens' placement, where 'Q' and '.' both indicate a queen and an empty space respectively.n皇后问题,题意就是求n×n矩阵中,每行放一个

2013-09-29 16:22:09 10551

原创 leetcode:Multiply Strings(字符串的乘法)【面试算法题】

题目:Given two numbers represented as strings, return multiplication of the numbers as a string.Note: The numbers can be arbitrarily large and are non-negative.题意给两个字符串表示的数字,计算他们的乘积。

2013-09-27 11:30:14 5434

原创 leetcode:Minimum Window Substring(最小覆盖子串)【面试算法题】

题目:Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n).For example,S = "ADOBECODEBANC"T = "ABC"Minimum window is "BANC".Note:If there is no such window in S that covers all cha

2013-09-27 02:29:00 6281

原创 leetcode:Minimum Path Sum(路线上元素和的最小值)【面试算法题】

Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path.Note: You can only move either down or right at any point in time.题意从左上到右下,所有可能的路径中,求经过的元素和最小值。

2013-09-27 01:00:32 3259

原创 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.题意求到叶子节点最短的距离。递归遍历,注意必须要到

2013-09-26 00:30:42 4224

原创 leetcode:Merge Two Sorted Lists (链接两个有序链表)【面试算法题】

题目:Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.题意链接两个有序链表。

2013-09-26 00:18:17 3795 3

原创 leetcode:Merge Sorted Array(合并两个有序数组到其中一个数组中)【面试算法题】

题目:Given two sorted integer arrays A and B, merge B into A as one sorted array.Note:You may assume that A has enough space to hold additional elements from B. The number of elements initialized in A and B are m and n respectively.题意要把两个有序的数组合并到他们中的一个

2013-09-25 23:59:53 7256

原创 leetcode:Merge k Sorted Lists(按大小顺序连接k个链表)【面试算法题】

题目:Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.题意:把k个排序成一个有序链表。

2013-09-25 23:49:58 2235

原创 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].题意把相交的集合合并。按start排序,遍历的时候判断前后集合是否

2013-09-25 18:49:00 3503

原创 leetcode:Median of Two Sorted Arrays (找两个序列的中位数,O(log (m+n))限制) 【面试算法】

题目: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)).题意已只两个有序的序列,找到他们的中位数,复杂度要求O(log (m+n))。

2013-09-25 16:57:35 2359

原创 leetcode:Maximum Subarray(最大的连续子数组) 【面试算法】

题目:Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array [−2,1,−3,4,−1,2,1,−5,4],the contiguous subarray [4,−1,2,1] has the largest sum = 6.题意 求连续的子串和最大。

2013-09-23 22:21:03 2356

原创 leetcode:Maximum Depth of Binary Tree(计算二叉树深度) 【面试算法】

题目:Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.查找二叉树的深度,递归去做,注意判断边界就好了。

2013-09-21 19:15:25 2271

原创 Maximal Rectangle (求矩阵的最大的子矩阵) 【面试算法leetcode】

题目:Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and return its area.题意有一个01组成的矩阵,找到其中面积最大的,全部由1构成的子矩阵。

2013-09-21 17:37:04 14087

原创 Longest Valid Parentheses(最长的括号匹配)【面试算法leetcode】

题目:Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring.之前写过一题类似的,是用栈去维护括号匹配的做法,因此想有没其他的做法。贪心的思想,和上一题类似,用双指针扫描,维护满足l>=r的字符串。

2013-09-21 16:13:31 2051

原创 leetcode: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 letters for "abcabcbb" is "abc", which the length is 3. For "bbbbb" the longest substring is "b", with the lengt

2013-09-21 15:35:18 2210

原创 Longest Palindromic Substring (最长回文串)【面试算法leetcode】

题目: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 longest palindromic substring.题意寻找并输出字符串中的最长回文串。

2013-09-21 15:14:36 2489

原创 Longest Consecutive Sequence (最长连续序列) 【面试算法leetcode】

Given [100, 4, 200, 1, 3, 2],The longest consecutive elements sequence is [1, 2, 3, 4]. Return its length: 4.Your algorithm should run in O(n) complexity. 题意在线性的时间内找到集合中元素组成的最长的连续序列。

2013-09-21 14:17:16 2262

原创 Longest Common Prefix(寻找最长前缀) 【leetcode】

题目:Write a function to find the longest common prefix string amongst an array of strings.题意找出所有字符串的最长前缀。j表示最长前缀的长度,不断增加j的值看是否满足条件。class Solution {public: string longestCommonPrefi

2013-09-21 13:27:31 8718

原创 Letter Combinations of a Phone Number (电话号码字母组合) 【leetcode】

题目:Given a digit string, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephone buttons) is given below.题意就

2013-09-21 12:46:42 3389

原创 Length of Last Word (最后一个单词的长度) 【leetcode】

题目:Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string.If the last word does not exist, return 0.Note: 

2013-09-20 22:14:47 2114

原创 Largest Rectangle in Histogram (直方图中最大面积) 【leetcode】

题目: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

2013-09-20 21:36:22 7174

原创 Jump Game II (最小步数到达终点,贪心) 【leetcode】

题目: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 position.Your

2013-09-20 19:33:17 14536

原创 Jump Game (能否到达终点,贪心) 【leetcode】

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 position.Determine i

2013-09-20 18:16:58 3090

原创 Interleaving String (字符串组合,动态规划) 【leetcoode】

题目: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 = "aadbbbacc

2013-09-20 18:07:59 2019

原创 Integer to Roman (罗马数字转换) 【leetcode】

题目:Given an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999.科普了一下表达方式,理解了就不复杂了。I = 1;V = 5;X = 10;L = 50;C = 100;D = 500;M = 1000;

2013-09-20 16:09:30 18635 3

原创 Insert Interval (区间的覆盖合并) 【leetcode】

题目:Given 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 according to their start ti

2013-09-20 15:52:26 2793

原创 Implement strStr() (匹配字符串问题,哈希解法) 【leetcode】

题目:Implement strStr().Returns a pointer to the first occurrence of needle in haystack, or null if needle is not part of haystack就是匹配字符串,返回原串中最先出现的指针。暴力就不说了,kmp也做多了,我写了一个哈希处理的方法,复杂度也是O(n)。因为都

2013-09-19 13:32:38 2346

原创 Gray Code (格雷码编码) 【leetcode】

题目:The gray code is a binary numeral system where two successive values differ in only one bit.Given a non-negative integer n representing the total number of bits in the code, print the

2013-09-19 01:08:30 2956

原创 Generate Parentheses (括号匹配)【leetcode】

题目: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:"((()))", "(()())", "(())()", "()(())",

2013-09-19 00:41:42 1533

原创 Flatten Binary Tree to Linked List (二叉树转前序链表)【leetcode】

题目: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:

2013-09-18 23:58:01 4648

原创 First Missing Positive (寻找第一个丢失的正数)【leetcode】

题目: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 uses

2013-09-18 16:19:01 3750

原创 Submission Details (两个字符串的最小距离)【leetcode】

题目: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

2013-09-18 01:08:44 2298

原创 Divide Two Integers (只用加减法做除法,logn复杂度) 【leetcode】

题目:Divide two integers without using multiplication, division and mod operator.就是做一个除法运算不能用乘法,除法(废话),去摸。有意思的题目,我的思路就是先预处理,num存除数的幂,sum存除数的倍数,从第一个比被除数小的sum开始减,并累加除数的倍数,复杂度logn。挂了两次,第一次傻逼了忘考虑正负,

2013-09-17 23:48:34 2918

原创 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

2013-09-17 23:02:35 1578

原创 Decode Ways(如何解码) 【leetcode】

题目:A message containing letters from A-Z is being encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26Given an encoded message containing digits, determine the total

2013-09-17 17:54:12 1075

原创 Convert Sorted List to Binary Search Tree (递增的链表转化成高度平衡的二叉查找树)【leetcode】

题目:Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST给一个递增的链表,转化成高度平衡的二叉查找树。先遍历一边算出链表的个数,在递归求解。注意就是左右字数划分的范围,还有右子树的头指针需要求出。/**

2013-09-17 17:00:06 2884

数学建模 算法大全 matlab描述

涵盖所有算法 有代码模板 是了解掌握数学建模算法必备

2011-10-30

空空如也

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

TA关注的人

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