
Leetcode
文章平均质量分 57
ljlstart
这个作者很懒,什么都没留下…
展开
-
leetcode-Linked List Cycle
Difficulty: MediumGiven a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?/** * Definition for singly-linked list. * struct ListNode {原创 2015-11-09 11:37:54 · 299 阅读 · 0 评论 -
leetcode-Search for a Range
Difficulty: 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(logn).If the ta原创 2015-11-09 23:08:44 · 288 阅读 · 0 评论 -
leetcode-Unique Paths II
Difficulty: MediumFollow 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 1 and 0 resp原创 2015-11-09 22:53:07 · 275 阅读 · 0 评论 -
leetcode-Triangle
Difficulty: 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[ [原创 2015-11-10 23:34:42 · 306 阅读 · 0 评论 -
leetcode-Sum Root to Leaf Numbers
Difficulty: MediumGiven a binary tree containing digits from0-9 only, each root-to-leaf path could represent a number.An example is the root-to-leaf path1->2->3 which represents the number原创 2015-11-09 21:55:31 · 517 阅读 · 0 评论 -
leetcode-Linked List Cycle II
Difficulty: MediumGiven a linked list, return the node where the cycle begins. If there is no cycle, returnnull.Note: Do not modify the linked list.Follow up:Can you solve it without using原创 2015-11-09 11:49:00 · 310 阅读 · 0 评论 -
leetcode-Binary Tree Paths
Difficulty:Easy Given a binary tree, return all root-to-leaf paths.For example, given the following binary tree: 1 / \2 3 \ 5All root-to-leaf paths are:["1->2->5", "1->3"]/原创 2015-11-06 22:46:16 · 314 阅读 · 0 评论 -
leetcode-Majority Element
Difficulty:Easy Given an array of size n, find the majority element. The majority element is the element that appears more than⌊ n/2 ⌋ times.You may assume that the array is non-empty and th原创 2015-11-06 20:32:07 · 233 阅读 · 0 评论 -
leetcode-Pascal's Triangle
Difficulty:Easy Given numRows, generate the first numRows of Pascal's triangle.For example, given numRows = 5,Return[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1]]class S原创 2015-11-06 19:41:52 · 282 阅读 · 0 评论 -
leetcode-Ugly Number 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 of the first 10原创 2015-10-21 23:49:45 · 344 阅读 · 0 评论 -
leetcode-Remove Linked List Elements
Difficulty: EasyRemove all elements from a linked list of integers that have valueval.ExampleGiven: 1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6, val = 6Return: 1 --> 2 --> 3 --> 4 --> 5/** *原创 2015-11-07 22:40:54 · 300 阅读 · 0 评论 -
leetcode-Remove Duplicates from Sorted List
Difficulty: EasyGiven a sorted linked list, delete all duplicates such that each element appear onlyonce.For example,Given 1->1->2, return 1->2.Given 1->1->2->3->3, return 1->2->3./** *原创 2015-11-07 22:21:36 · 289 阅读 · 0 评论 -
leetcode-Reverse Integer
Difficulty: EasyReverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321class Solution { public: int reverse(int x) {原创 2015-11-10 20:13:57 · 304 阅读 · 0 评论 -
leetcode-Unique Paths
Difficulty: MediumA 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 robot is原创 2015-11-09 22:40:02 · 296 阅读 · 0 评论 -
leetcode-Symmetric Tree
Difficulty: Easy Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree is symmetric: 1 / \ 2 2 / \ / \3 4 4 3原创 2015-11-10 20:00:17 · 308 阅读 · 0 评论 -
leetcode-Binary Tree Maximum Path Sum
Difficulty: HardGiven a binary tree, find the maximum path sum.For this problem, a path is defined as any sequence of nodes from some starting node to any node in the tree along the parent-child原创 2015-11-09 22:16:10 · 301 阅读 · 0 评论 -
leetcode-Minimum Depth of Binary Tree
Difficulty: EasyGiven 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./** * Definition fo原创 2015-11-06 00:08:58 · 295 阅读 · 0 评论 -
leetcode-Two Sum
Given 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 to the target, where原创 2015-11-03 21:36:52 · 266 阅读 · 0 评论 -
leetcode-Combination Sum
Given a set of candidate numbers (C) and a target number (T), find all unique combinations inC where the candidate numbers sums to T.The same repeated number may be chosen from C unlimited numbe原创 2015-11-02 15:03:44 · 260 阅读 · 0 评论 -
leetcode-Combination Sum III
Find all possible combinations of k numbers that add up to a numbern, given that only numbers from 1 to 9 can be used and each combination should be a unique set of numbers.Ensure that numbers wit原创 2015-11-02 15:24:42 · 280 阅读 · 0 评论 -
leetcode-Kth Smallest Element in a BST
Given a binary search tree, write a function kthSmallest to find thekth smallest element in it.Note: You may assume k is always valid, 1 ≤ k ≤ BST's total elements.Follow up:What if the BST原创 2015-11-02 16:13:54 · 376 阅读 · 0 评论 -
leetcode- Longest Common Prefix
Write a function to find the longest common prefix string amongst an array of strings.class Solution { int maxCountLength(string &a,string &b,int minLength){ //返回两个字符串的前缀长度,minLength表示上一次比较结果的前原创 2015-11-02 23:02:56 · 316 阅读 · 0 评论 -
leetcode-Word Search
Given 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 horizontally or vertically n原创 2015-11-02 18:03:38 · 322 阅读 · 0 评论 -
leetcode-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 lowest common ancestor is defined between two nodes原创 2015-11-02 15:40:05 · 386 阅读 · 0 评论 -
leetcode-Minimum Path Sum
Difficulty: MediumGiven a m x n grid filled with non-negative numbers, find a path from top left to bottom right whichminimizes the sum of all numbers along its path.Note: You can only move ei原创 2015-11-09 22:32:21 · 415 阅读 · 0 评论 -
leetcode-Kth Largest Element in an Array
Difficulty: MediumFind 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 example,Given [3,2,1,5,6,4] a原创 2015-11-11 12:09:59 · 320 阅读 · 0 评论 -
leetcode-Permutations
Difficulty: MediumGiven 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,2,1原创 2015-11-07 20:48:02 · 278 阅读 · 0 评论 -
leetcode-Summary Ranges
Difficulty: Easy Given a sorted integer array without duplicates, return the summary of its ranges.For example, given [0,1,2,4,5,7], return["0->2","4->5","7"].class Solution {public: ve原创 2015-11-06 20:23:23 · 324 阅读 · 0 评论 -
leetcode-Pascal's Triangle II
Difficulty:Easy 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(k) extra space?原创 2015-11-06 19:30:22 · 362 阅读 · 0 评论 -
leetcode-Excel Sheet Column Number
EasyRelated to question Excel Sheet Column TitleGiven a column title as appear in an Excel sheet, return its corresponding column number.For example: A -> 1 B -> 2 C -> 3 ..原创 2015-11-04 21:30:28 · 352 阅读 · 0 评论 -
leetcode-Contains Duplicate II
Difficulty: Easy Given an array of integers and an integer k, find out whether there are two distinct indicesi and j in the array such that nums[i] = nums[j] and the difference betweeni and j原创 2015-11-04 20:37:04 · 291 阅读 · 0 评论 -
leetcode-Single Number III
Difficulty:Medium Given an array of numbers nums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once.For原创 2015-11-04 23:12:08 · 319 阅读 · 0 评论 -
leetcode-Same Tree
Difficulty:EasyGiven two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical and the nodes have the same val原创 2015-11-04 20:23:29 · 294 阅读 · 0 评论 -
leetcode-Excel Sheet Column Title
Given a positive integer, return its corresponding column title as appear in an Excel sheet.For example 1 -> A 2 -> B 3 -> C ... 26 -> Z 27 -> AA 28 -> AB class Solu原创 2015-11-04 11:50:43 · 271 阅读 · 0 评论 -
leetcode-Number of Islands
Difficulty:Medium Given a 2d grid map of '1's (land) and'0's (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or v原创 2015-11-03 23:53:55 · 353 阅读 · 0 评论 -
leetcode-Minimum Size Subarray Sum
Given an array of n positive integers and a positive integer s, find the minimal length of a subarray of which the sum ≥ s. If there isn't one, return 0 instead.For example, given the array [2,3,1原创 2015-11-03 21:26:28 · 277 阅读 · 0 评论 -
leetcode-Product of Array Except Self
Total Accepted: 22035 Total Submissions: 57744 Difficulty: MediumGiven an array of n integers where n > 1, nums, return an arrayoutput such that output[i] is equal to the product of all the原创 2015-11-04 11:31:07 · 376 阅读 · 0 评论 -
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".原创 2015-11-03 21:09:01 · 335 阅读 · 0 评论 -
leetcode-Swap Nodes in Pairs
Difficulty:Medium Given a linked list, swap every two adjacent nodes and return its head.For example,Given 1->2->3->4, you should return the list as 2->1->4->3.Your algorithm should use on原创 2015-11-03 23:10:13 · 312 阅读 · 0 评论 -
leetcode-Longest Increasing Subsequence
MediumGiven an unsorted array of integers, find the length of longest increasing subsequence.For example,Given [10, 9, 2, 5, 3, 7, 101, 18],The longest increasing subsequence is [2, 3, 7,原创 2015-11-04 12:03:25 · 332 阅读 · 0 评论