
leetcode
文章平均质量分 80
fangjian1204
这个作者很懒,什么都没留下…
展开
-
leetcode 之 Scramble String
leetcode 之 Scramble String原创 2014-09-07 09:08:29 · 1310 阅读 · 0 评论 -
leetcode之Median of Two Sorted Arrays
Median of Two Sorted ArraysThere 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 (原创 2014-08-27 14:04:40 · 1118 阅读 · 0 评论 -
leetcode 之 Rotate Image
Rotate Image原创 2014-09-10 11:03:02 · 1154 阅读 · 0 评论 -
leetcode 之 Validate Binary Search Tree
Validate Binary Search Tree原创 2014-08-26 10:09:18 · 997 阅读 · 0 评论 -
Valid Sudoku 和 Sudoku Solver
题目一:Valid SudokuDetermine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules.The Sudoku board could be partially filled, where empty cells are filled with the character '.'.原创 2014-08-12 15:13:50 · 794 阅读 · 0 评论 -
Populating Next Right Pointers in Each Node
题目一:Populating Next Right Pointers in Each NodeGiven a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Popul原创 2014-08-12 08:50:53 · 934 阅读 · 0 评论 -
leetcode 之 Symmetric Tree 镜像树
Symmetric Tree原创 2014-08-26 10:55:10 · 2069 阅读 · 0 评论 -
leetcode之Divide Two Integers
Divide Two IntegersDivide two integers without using multiplication, division and mod operator.分析:原创 2014-09-08 21:30:43 · 1197 阅读 · 0 评论 -
leetcode 之 Jump Game
Jump Game原创 2014-09-08 10:23:30 · 1238 阅读 · 0 评论 -
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 complete at most one transaction (ie,原创 2014-09-08 08:58:22 · 1230 阅读 · 0 评论 -
leetcode之Gray Code
Gray CodeThe 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 cod原创 2014-08-27 14:20:34 · 1130 阅读 · 0 评论 -
归并排序的应用
一、归并排序算法思路就是把数组分成左右两个部分,然后再进行归并两个有序表void merge(int* num,int start,int mid,int end,int* copy){ int i = start,m = mid,j = mid+1,n = end,k=start; while(i <= m && j <= n) { if(num[i] < num[j])co原创 2014-08-27 11:20:09 · 1066 阅读 · 0 评论 -
leetcode之Word Break
Word BreakGiven 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",原创 2014-09-06 17:31:38 · 1135 阅读 · 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 operati原创 2014-08-18 19:17:18 · 1477 阅读 · 0 评论 -
leetcode 之 Recover Binary Search Tree
Recover Binary Search TreeTwo 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 s原创 2014-08-15 19:21:14 · 914 阅读 · 0 评论 -
leetcode 之 Permutation Sequence
Permutation SequenceThe 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):原创 2014-08-28 10:40:14 · 1095 阅读 · 0 评论 -
编程之美之高效安排见面会
对于原题,书上写的很详细,即图的着色问题,这里主要看第一个扩展和leetcode上相关的问题扩展问题一:简单的说就是:有 N 个面试要同时进行, 他们的面试时间分别是 B[i], E[i]. 我们希望将这N个面试安排在若干地点, 不同的面试在同一时间不能再相同的面试点. 问至少需要多少个面试点思路:先按照开始时间排序,对每个节点赋颜色值时,在它之前开始并且有时间重叠的区域的颜色不能使用原创 2014-08-14 19:06:36 · 1427 阅读 · 0 评论 -
leetcode 之 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.For example,X X X XX O O X原创 2014-08-28 13:26:50 · 980 阅读 · 0 评论 -
编程之美之电话号码对应英语单词
题目一:根据电话上字母和数字的对应关系,用一个有意义的单词来表述一个电话号码,如用computer表示26678837题目二:反过来,给定一个电话号码,是否可以用一个单词来表示呢?怎样表示最快呢?显然不是所有的电话号码都可以对应到单词上去首先来看看leetcode上一个类似的题目:Letter Combinations of a Phone Number G原创 2014-08-15 14:34:20 · 1697 阅读 · 0 评论 -
leetcode 之 Unique Paths
Unique PathsA robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).The robot can only move either down or right at any point in time. The r原创 2014-08-27 16:20:35 · 1047 阅读 · 0 评论 -
leetcode之Search in Rotated Sorted Array,剑指offer之旋转数组的最小数字
输入一个递增数组的旋转,原创 2014-08-27 15:52:49 · 1362 阅读 · 0 评论 -
leetcode 之 Median of Two Sorted Arrays
Median of Two Sorted Arrays原创 2014-09-08 11:32:06 · 1183 阅读 · 0 评论 -
leetcode 之 Triangle
Triangle原创 2014-09-08 15:09:26 · 1041 阅读 · 0 评论 -
leetcode 之 Flatten Binary Tree to Linked List
剑指offer二叉树变双链表原创 2014-09-07 17:34:13 · 929 阅读 · 0 评论 -
leetcode 之 Word Ladder
Word LadderGiven 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 t原创 2014-09-06 20:22:43 · 1216 阅读 · 0 评论 -
leetcode之Partition List,Reverse Nodes in k-Group
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 order of原创 2014-08-21 18:46:19 · 1165 阅读 · 0 评论 -
leetcode之通配符
Wildcard MatchingImplement wildcard pattern matching with support for '?' and '*'.'?' Matches any single character.'*' Matches any sequence of characters (including the empty sequen原创 2014-08-18 17:55:57 · 1365 阅读 · 0 评论 -
leetcode解题目录
参考文献:http://blog.csdn.net/lanxu_yy/article/details/17848219 不过本文准备用超链接的方式连接到相应解答页面,不断更新中题目算法数据结构注意事项Clone GraphBFS哈希表Word Ladder IIBFS哈希表Surrounded Regions原创 2014-08-11 08:20:30 · 1388 阅读 · 0 评论 -
leetcode之Container With Most Water 和Trapping Rain Water
Container With Most Water Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line原创 2014-08-22 16:04:28 · 1348 阅读 · 0 评论 -
leetcode之Combination Sum
Combination SumGiven 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 chosen原创 2014-08-22 15:17:27 · 1049 阅读 · 0 评论 -
leetcode 之 Longest Common Prefix
Longest Common Prefix Write a function to find the longest common prefix string amongst an array of strings.最长公共前缀最快的方法应该是使用后缀数组,但这里仅仅简单的使用了二重遍历,不过已经能提交leetcode了,面试的时候如果要是会后缀数组,应该很牛逼了,不过我不会,所以原创 2014-08-20 14:06:05 · 1105 阅读 · 0 评论 -
待字闺中之interleave字符串分析
题目来源,待字闺中,原创@陈利人 ,欢迎大家继续关注微信公众账号“待字闺中”3个字符串a,b,c。判断c是否是a和b的interleave,也就是c中应该有a,b中所有字 符,并且c中字符顺序和a,b中一样。比如,1. a = "ef" b = "gh" c = "egfh" return true;2. a = "ef" b = "gh" c = "ehgf" return原创 2014-07-21 15:58:21 · 1233 阅读 · 0 评论 -
leetcode 之 Distinct Subsequences
Distinct SubsequencesGiven 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 b原创 2014-09-06 21:20:26 · 1177 阅读 · 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-09-06 22:19:20 · 1056 阅读 · 0 评论 -
大整数的乘法运算
思想:每次取第二个数的最高位进行一次乘法,把结果乘以10和下一次结果相加,题目来源:leetcodeclass Solution {public: //一个整数乘以一个个位数 string multOneBit(string num,int data) { int i = num.size() - 1,carry = 0; string res;原创 2014-08-11 18:52:06 · 1124 阅读 · 0 评论 -
leetcode之n皇后问题
leetcode上有两个关于n皇后的问题,两个题目基本是一样的,只是第二个是把所有的排法求出来。n皇后最简单的就是用递归,每次判断一行的一个位置,如果合法,就判断下一行,不合法再判断下一个位置N-Queens II Follow up for N-Queens problem.Now, instead outputting board configuration原创 2014-08-11 14:13:14 · 2051 阅读 · 0 评论 -
leetcode 之 Longest Valid Parentheses
leetcode中和括号匹配相关的问题共有三个,分别是:Valid Parentheses Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.The brackets m原创 2014-08-18 18:57:31 · 1478 阅读 · 0 评论 -
编程之美之最短摘要生成
书上给出了最短摘要的描述即算法,简单来说就是:扫描过程始终保持一个[pBegin,pEnd]的range,初始化确保[pBegin,pEnd]的range里包含所有关键字 。然后每次迭代,尝试调整pBegin和pEnd: 1.pBegin递增,直到range无法包含所有关键字 2.pEnd递增,直到range重新包含所有关键字 计算新的range,与旧的range相比,看是否缩短了原创 2014-08-15 13:59:51 · 1854 阅读 · 0 评论 -
先序+中序和中序+后序建树
思路:先序的第一个元素和后序的最后一个元素是当前子树的根,然后遍历中序序列,找到左右子树的分界线,递归建左子树和右子树。class Solution {public: /*由于是oj,这里假设给的序列是合法的,正常情况是需要判断不合法情况的 */ TreeNode *buildTree(vector &inorder, vector &postorder,int instar原创 2014-08-11 18:11:07 · 2987 阅读 · 0 评论 -
回文串问题总结
回文串的问题很经典,也很常见,涉及到递归,循环,动态规划等方面,这里总结一下几种类型,供以后回顾,有问题请大家指正1、回文串的判断 leetcode上的题目bool isPalindrome(const char* src){ if(src == NULL)return true; int end = strlen(src)-1,begin = 0; while(beg原创 2014-07-24 14:48:48 · 5478 阅读 · 2 评论