LeetCode
文章平均质量分 70
AllZ
金猴奋起千钧棒,玉宇澄清万里埃。
展开
-
[LeetCode] Minimum Depth of Binary Tree
前言LeetCode 的blabla Tree系列的又一道题,Recursive solution很好理解。题目https://leetcode.com/problems/minimum-depth-of-binary-tree/ Given a binary tree, find its minimum depth. The minimum depth is the number of nod原创 2016-03-01 21:21:44 · 311 阅读 · 0 评论 -
[LeetCode] Remove Element 分析
Remove Element算是LeetCode的一道水题,不过这题也有多种做法,现就我所知的几种做一点讨论。题目链接:https://leetcode.com/problems/remove-element/ 题目描述:Given an array and a value, remove all instances of that value in place and return th原创 2016-02-02 14:03:05 · 447 阅读 · 0 评论 -
[LeetCode] Remove Duplicates from Sorted Array
前言Remove Duplicates from Sorted Array是比较平易近人的一道题,做的时候直接模拟AC,后来在网上看到有STL做法,利用现成的函数和工具就是简便啊。题目题目链接描述如下:Given a sorted array,remove the duplicates in place such that each element ap原创 2016-02-02 12:39:16 · 503 阅读 · 0 评论 -
[LeetCode] Container With Most Water 简要分析
前言这题非要说贪心的话也算是吧,不过最主要的特征还是双指针。LC的题好像不少都是扔倆头尾指针然后遍历一遍完事儿的。这道题倒是“短板效应”的不错体现了。题目题目链接Given n non-negative integers a1, a2, …, an, where each represents a point at coordinate (i, ai). n vertical lines are d原创 2015-12-04 16:42:34 · 440 阅读 · 0 评论 -
[LeetCode] Intersection of Two Linked Lists 题解
Intersection of Two Linked Lists也是LeetCode的Linked List Tag下的一道题,网上流传着多种做法。原创 2016-03-19 11:00:27 · 396 阅读 · 0 评论 -
[LeetCode] Insertion Sort List
前言Insertion Sort List算是Linked List tag下的一道中等难度的题吧,可以用来复习链表的选择排序操作。解法很固定,没什么讨论的余地。题目https://leetcode.com/problems/insertion-sort-list/ Sort a linked list using insertion sort. 排序一个链表,指定必须采用插入排序算法。分析插入原创 2016-03-19 21:30:02 · 346 阅读 · 0 评论 -
[LeetCode] Plus One 简要分析
前言Plus one是一道数组相关的题,其实就是高精度加法。题目https://leetcode.com/problems/plus-one/ Given a non-negative number represented as an array of digits, plus one to the number. The digits are stored such that the most原创 2016-03-08 13:09:06 · 333 阅读 · 0 评论 -
[LeetCode] 3Sum分析与C/C++解法
前言3Sum算是LeetCode最经典的十几道题之一了,据说在面试中出现的频率相当高。所以在这里花点篇幅讨论一下此题。题目https://leetcode.com/problems/3sum/ Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all uniqu原创 2016-03-08 21:23:37 · 1054 阅读 · 0 评论 -
[LeetCode] Set Matrix Zeroes
前言Set Matrix Zeroes,一道LeetCode中十分经典的数组题,据说在笔试中出现频率不低。不过此题本质不难,要做到不适用额外空间就稍微要多想一下了。题目https://leetcode.com/problems/set-matrix-zeroes/ Given a m x n matrix, if an element is 0, set its entire row and co原创 2016-03-09 20:47:50 · 386 阅读 · 0 评论 -
如何求二进制表示中“1”的个数
刚翻开《编程之美》, 中间就有一道我很眼熟的题,“求二进制中1的个数”。书中的题目描述如下:原创 2016-03-21 18:46:21 · 857 阅读 · 0 评论 -
[LeetCode] Validate Binary Search Tree
前言根据网上的LeetCode题目难度和出现频率表(里面都是最老的那些题目),Validate Binary Search Tree算是很重要的一道题了。 在Tree系列中也是举足轻重的一道题。题目https://leetcode.com/problems/validate-binary-search-tree/ Given a binary tree, determine if it is a原创 2016-03-10 21:43:48 · 320 阅读 · 0 评论 -
[LeetCode] Symmetric Tree
前言一道树相关的简单题,判断二叉树是否对称。题目https://leetcode.com/problems/symmetric-tree/ Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).分析这类题一般都有递归和非递归两种基本思路。对于此题而言,递归方式相对e原创 2016-02-29 22:06:20 · 327 阅读 · 0 评论 -
[LeetCode] Valid Parentheses
前言Valid Parentheses是Leetcode的一道基础题,考察括号匹配算法,使用栈结构。题目题目描述Given a string containing just the characters ‘(‘, ‘)’, ‘{‘, ‘}’, ‘[’ and ‘]’, determine if the input string is valid.The brackets must close in原创 2016-02-07 09:20:33 · 228 阅读 · 0 评论 -
[LeetCode] Linked List Cycle 与 Linked List Cycle II
前言Linked List Cycle 与 Linked List Cycle II是LeetCode链表系列很经典的两道题,值得研究一下。题目https://leetcode.com/problems/linked-list-cycle/ https://leetcode.com/problems/linked-list-cycle-ii/Linked List CycleGiven a lin原创 2016-03-07 14:37:13 · 306 阅读 · 0 评论 -
[LeetCode] Same Tree
前言Leetcode之blabla Tree系列的一道水题。题目https://leetcode.com/problems/same-tree/分析仍然是两种基本思路——递归与非递归,递归比较容易理解。具体见代码。代码Recursive solution, easy to understand.bool isSameTree(TreeNode* p, TreeNode* q) { if (!原创 2016-02-29 22:58:42 · 294 阅读 · 0 评论 -
[LeetCode] Maximum Depth of Binary Tree
前言LeetCode 的blabla Tree系列又一基础题,可配合 Minimum Depth of Binary Tree 一起练习。题解在此。题目https://leetcode.com/problems/maximum-depth-of-binary-tree/ Given a binary tree, find its maximum depth. The maximum depth原创 2016-03-01 21:33:35 · 334 阅读 · 0 评论 -
[LeetCode] Two Sum水过
刷LeetCode的第一题,TwoSum,基本算是水过。题目:https://leetcode.com/problems/two-sum/Given an array of integers, find two numbers such that they add up to a specific target number.The function twoSum shou原创 2015-12-04 10:29:48 · 568 阅读 · 0 评论 -
[LeetCode] Balanced Binary Tree 题解
前言LeetCode blabla Tree系列稍微不太水的一道题,很有使用价值(可以牵扯到AVL树的概念什么的)。递归仍然是不二选择。题目https://leetcode.com/problems/balanced-binary-tree/ Given a binary tree, determine if it is height-balanced. For this problem, a原创 2016-03-02 08:56:00 · 290 阅读 · 0 评论 -
[LeetCode] Unique Paths 题解
前言Unique Paths应该说是LeetCode动态规划系列中很亲民的一道题了(AC率比较高)。实际上,Dynamic Programming的题目一般关键都在于想出递推关系,成功写出准确的循环解法。题目题目链接:https://leetcode.com/problems/unique-paths/ A robot is located at the top-left corner of a原创 2016-03-02 18:03:15 · 574 阅读 · 0 评论 -
[LeetCode] House Robber 题解
前言House Robber算是LeetCode动态规划tag下的入门题,相当简单。题目题目链接:https://leetcode.com/problems/house-robber/ You are a professional robber planning to rob houses along a street. Each house has a certain amount of mon原创 2016-03-03 14:57:06 · 510 阅读 · 0 评论 -
[LeetCode] Binary Tree Traversal 系列
前言LeetCode有三道考察二叉树遍历的基础题,即Binary Tree XXXOrder Traversal 系列,分别为Preorder,inorder,以及postorder。 先序,中序,后序遍历都比较简单,下面讨论递归方法。题目https://leetcode.com/problems/binary-tree-preorder-traversal/ https://leetcode.原创 2016-03-04 12:28:35 · 290 阅读 · 0 评论 -
[LeetCode] Single Number & Single Number III
Single Number三步曲是LeetCode诸多系列题中流传最广的一个(也许没有之一?),这里放在一起讨论一下。由于Single Number II稍微难一些,所以这篇文章先讨论I和III。原创 2016-03-16 08:06:46 · 411 阅读 · 0 评论 -
[LeetCode] Missing Number
前言Missing Number是一道和Single Number很像的题(无论是从名字还是解法的角度而言),具体思路并不难,做法倒是不少。题目https://leetcode.com/problems/missing-number/ Given an array containing n distinct numbers taken from 0, 1, 2, …, n, find the on原创 2016-03-17 20:57:53 · 429 阅读 · 0 评论 -
[LeetCode] Bulb Switcher
前言Bulb Switcher是LeetCode上的一道”脑筋急转弯”类题目,颇有趣味性。难度并不大,实际上想通数学规律后,此题只需要一行代码。题目https://leetcode.com/problems/bulb-switcher/ There are n bulbs that are initially off. You first turn on all the bulbs. Then,原创 2016-03-06 10:39:04 · 312 阅读 · 0 评论 -
[LeetCode] Valid Anagram 题解
前言题目https://leetcode.com/problems/valid-anagram/Given two strings s and t, write a function to determine if t is an anagram of s. For example, s = “anagram”, t = “nagaram”, return true. s = “rat”, t原创 2016-03-18 10:53:55 · 415 阅读 · 0 评论 -
[LeetCode] Find Minimum in Rotated Sorted Array 题解
前言Find Minimum in Rotated Sorted Array这道题存在的价值,大概就是让大家直观感受一下LeetCode上二分的题目真的很多。。。题目https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/ Suppose a sorted array is rotated at some pivot u原创 2016-04-28 20:58:19 · 505 阅读 · 0 评论