![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
LeetCode
失失落沙洲
一个简单的人
展开
-
[LeetCode]28 实现子字符串匹配
Implement strStr() (实现子字符串匹配)【难度:Easy or Medium】 Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack. 返回在主字符串中出现的第一个子字符串的下标,如果不原创 2016-03-06 13:58:16 · 3032 阅读 · 0 评论 -
[LeetCode]236 二叉树的最近公共父亲节点
Lowest Common Ancestor of a Binary Tree(二叉树的最近公共父亲节点)Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.According to the definition of LCA on Wikipedia: “The lowe原创 2016-02-28 20:52:17 · 6802 阅读 · 0 评论 -
[LeetCode]106 根据中序遍历和后序遍历构建二叉树
Construct Binary Tree from Inorder and Postorder Traversal(根据中序遍历和后序遍历构建二叉树)【难度:Medium】 Given inorder and postorder traversal of a tree, construct the binary tree.Note: You may assume that duplicates原创 2016-02-29 14:23:25 · 2697 阅读 · 1 评论 -
[LeetCode]105 根据先序遍历和中序遍历构建二叉树
Construct Binary Tree from Preorder and Inorder Traversal(根据先序遍历和中序遍历构建二叉树)【难度:Medium】 Given preorder and inorder traversal of a tree, construct the binary tree.Note: You may assume that duplicates d原创 2016-02-29 14:32:14 · 1482 阅读 · 0 评论 -
[LeetCode]1 两者之和
Two Sum(两者之和)【难度:Easy】 Given an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would have exactly one solution. Example原创 2016-02-29 20:37:12 · 306 阅读 · 0 评论 -
[LeetCode]15 三者之和
3Sum(三者之和)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)原创 2016-02-29 21:32:26 · 256 阅读 · 0 评论 -
[LeetCode]16 最接近的三者之和
3Sum Closest(最接近的三者之和)【难度:Medium】 Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume原创 2016-02-29 22:32:13 · 373 阅读 · 0 评论 -
[LeetCode]67 二进制相加
Add Binary(二进制相加)【难度:Easy】 Given two binary strings, return their sum (also a binary string).For example, a = “11” b = “1” Return “100”.给定两个二进制数的字符串,以字符串形式返回他们的和。 如: a = “11” b = “1” return “10原创 2016-03-01 16:11:40 · 310 阅读 · 0 评论 -
[LeetCode]136 单一的数字
Single Number(单一的数字)【难度:Medium】 Given an array of integers, every element appears twice except for one. Find that single one.Note: Your algorithm should have a linear runtime complexity. Could you im原创 2016-03-01 16:29:46 · 298 阅读 · 0 评论 -
[LeetCode]235 二叉查找树的最近公共父亲节点
Lowest Common Ancestor of a Binary Search Tree(二叉查找树的最近公共父亲节点)【难度:Easy】 Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.According to the definitio原创 2016-02-28 20:39:10 · 3139 阅读 · 0 评论 -
[LeetCode]34 范围搜索
Search for a Range(范围搜索)【难度:Medium】 Given a sorted array of integers, find the starting and ending position of a given target value.Your algorithm’s runtime complexity must be in the order of O(log n)原创 2016-02-28 18:40:57 · 638 阅读 · 0 评论 -
[LeetCode]147 链表插入排序
Insertion Sort List(链表插入排序)【难度:Medium】 Sort a linked list using insertion sort. 对一个链表使用插入排序。解题思路基于插入排序的思想,从链表头开始遍历,找到第一个大于当前节点的链表节点,进行链表间的交换操作。由于链表的操作比较麻烦,因此链表的插入排序相比于数组的插入排序要复杂。c++代码如下:/** * Defini原创 2016-02-28 17:13:53 · 361 阅读 · 0 评论 -
[LeetCode]43 高精度乘法
Multiply Strings(高精度乘法)【难度:Medium】 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. 实现高精度非负整原创 2016-03-07 20:49:47 · 1605 阅读 · 0 评论 -
[LeetCode] 104 二叉树最大深度
[LeetCode] 104. Maximum Depth of Binary Tree【难度:Easy】 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 farthes原创 2016-02-28 00:23:04 · 2765 阅读 · 0 评论 -
[LeetCode] 226 翻转二叉树
Invert Binary Tree(翻转二叉树)【难度:Easy】 Invert a binary tree. to 对一棵二叉树进行镜像翻转。解题思路根据二叉树的结构特点,使用递归的思想,在根节点root非空时,分别对左子树和右子树进行递归操作,更换root->left和root->right的值,由局部到整体完成整棵二叉树的翻转。c++代码如下:/** * Definition原创 2016-02-28 00:40:11 · 557 阅读 · 0 评论 -
[LeetCode]62 不同的路径总数
Unique Paths(不同的路径总数)【难度:Medium】 A 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原创 2016-02-28 13:31:29 · 2968 阅读 · 2 评论 -
[LeetCode]63 不同的路径总数之二
Unique Paths II(不同的路径总数之二)【难度:Medium】 Follow up for “Unique Paths”:Now consider if some obstacles are added to the grids. How many unique paths would there be?An obstacle and empty space is marked as原创 2016-02-28 13:42:33 · 1204 阅读 · 0 评论 -
[LeetCode]86 链表划分
Partition List(链表划分)【难度:Medium】 Given 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 o原创 2016-02-28 14:28:56 · 578 阅读 · 0 评论 -
[LeetCode]96 不同二分查找树
Unique Binary Search Trees(不同的二分查找树)【难度:Medium】 Given n, how many structurally unique BST’s (binary search trees) that store values 1…n?For example, Given n = 3, there are a total of 5 unique BST’s.原创 2016-02-28 16:01:39 · 312 阅读 · 0 评论 -
[LeetCode]95 不同二分查找树之二
Unique Binary Search Trees II(不同二分查找树之二)【难度:Medium】 Given n, generate all structurally unique BST’s (binary search trees) that store values 1…n.For example, Given n = 3, your program should return al原创 2016-02-28 16:15:42 · 687 阅读 · 0 评论 -
[LeetCode]33 旋转后的有序数组中的搜索
Search in Rotated Sorted Array(旋转后的有序数组中的搜索)【难度:hard or Easy】 Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).You are given a原创 2016-03-01 23:54:32 · 400 阅读 · 0 评论 -
[LeetCode]332 航程重建
Reconstruct Itinerary(航程重建)【难度:Medium】 Given a list of airline tickets represented by pairs of departure and arrival airports [from, to], reconstruct the itinerary in order. All of the tickets belong原创 2016-03-02 00:34:29 · 1922 阅读 · 0 评论 -
[LeetCode]39 和的组合形式
Combination Sum(和的组合形式)【难度:Medium】 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原创 2016-03-02 14:15:31 · 234 阅读 · 0 评论 -
[LeetCode]153 有序数组旋转后的最小值
Find Minimum in Rotated Sorted Array(找到有序数组旋转后的最小值)【难度:Medium】 Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).Find the minim原创 2016-03-06 15:01:52 · 541 阅读 · 0 评论 -
[LeetCode]154 有序数组旋转后的最小值 II
Find Minimum in Rotated Sorted Array II(找到有序数组旋转后的最小值 II)【难度:Medium】 Follow up for “Find Minimum in Rotated Sorted Array”: What if duplicates are allowed?Would this affect the run-time complexity? Ho原创 2016-03-06 15:06:46 · 365 阅读 · 0 评论 -
[LeetCode]2 两个数相加
Add Two Numbers(两个数相加)【难度:Medium】 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 t原创 2016-03-07 19:36:37 · 651 阅读 · 0 评论 -
[LeetCode]120 三角矩阵
Triangle(三角矩阵)【难度:Medium】 Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the following triangle[ [2原创 2016-03-09 14:14:50 · 419 阅读 · 0 评论 -
[LeetCode]201 区间按位与
Bitwise AND of Numbers Range(区间按位与)【难度:Medium】 Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers in this range, inclusive.For example, given the range [5, 7],原创 2016-03-09 14:30:21 · 1493 阅读 · 0 评论 -
[LeetCode]313 超级丑数
Super Ugly Number(超级丑数)【难度:Medium】 Write a program to find the nth super ugly number.Super ugly numbers are positive numbers whose all prime factors are in the given prime list primes of size k. For e原创 2016-03-13 21:30:18 · 1347 阅读 · 0 评论 -
[LeetCode]264 丑数 II
Ugly Number II(丑数 II)Write a program to find the n-th ugly number.Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 1, 2, 3, 4, 5, 6, 8, 9, 10, 12 is the sequence原创 2016-03-13 21:40:35 · 402 阅读 · 0 评论 -
[LeetCode]198 强盗入屋
House Robber(强盗入屋)【难度:Easy】 You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of原创 2016-03-13 22:24:35 · 504 阅读 · 0 评论 -
[LeetCode]274 H指数
H-Index(H指数)【难度:Medium】 Given an array of citations (each citation is a non-negative integer) of a researcher, write a function to compute the researcher’s h-index.According to the definition of h-ind原创 2016-03-06 14:28:39 · 504 阅读 · 0 评论 -
[LeetCode]145 二叉树后序遍历
Binary Tree Postorder Traversal(二叉树后序遍历)【难度:Medium】 Given a binary tree, return the postorder traversal of its nodes’ values.For example: Given binary tree {1,#,2,3}, return [3,2,1].Note: Recursiv原创 2016-03-05 17:32:33 · 969 阅读 · 0 评论 -
[LeetCode]94 二叉树中序遍历
Binary Tree Inorder Traversal(二叉树中序遍历)【难度:Medium】 Given a binary tree, return the inorder traversal of its nodes’ values.For example: Given binary tree {1,#,2,3}, return [1,3,2].Note: Recursive so原创 2016-03-05 17:25:40 · 1167 阅读 · 0 评论 -
[LeetCode]40 和的组合 II
Combination Sum II(和的组合 II)【难度:Medium】 Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.Each number in C may原创 2016-03-03 00:07:41 · 320 阅读 · 0 评论 -
[LeetCode]215 数组第k大的数
Kth Largest Element in an Array(数组第k大的数)【难度:Medium】 Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element.For exa原创 2016-03-04 00:18:03 · 15581 阅读 · 1 评论 -
[LeetCode]334 三个递增数字子序列
Increasing Triplet Subsequence(三个递增数字子序列)【难度:Medium】 Given an unsorted array return whether an increasing subsequence of length 3 exists or not in the array.Formally the function should: Return true原创 2016-03-04 18:26:53 · 1236 阅读 · 0 评论 -
[LeetCode]4 两个有序数组的中位数
Median of Two Sorted Arrays(两个有序数组的中位数)【难度:hard】 There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity sho原创 2016-03-05 01:32:24 · 14801 阅读 · 3 评论 -
[LeetCode]44 通配符的匹配
Wildcard Matching(通配符的匹配)【难度:Hard】 Implement wildcard pattern matching with support for ‘?’ and ‘*’.'?' Matches any single character.'*' Matches any sequence of characters (including the empty sequen原创 2016-03-05 15:24:23 · 485 阅读 · 0 评论 -
[LeetCode]268 消失的数字
Missing Number(消失的数字)【难度:Medium】 Given an array containing n distinct numbers taken from 0, 1, 2, …, n, find the one that is missing from the array.For example, Given nums = [0, 1, 3] return 2.Note:原创 2016-03-05 15:36:12 · 866 阅读 · 0 评论