Quantcast
Channel: 书影 - Entries for the tag leetcode
Browsing all 559 articles
Browse latest View live

[LeetCode]Game of Life

题目描述:According to the Wikipedia's article: "The Game of Life, also known simply as Life, is a cellular automaton devised by the British mathematician John Horton Conway in 1970."Given a board with m by...

View Article


[LeetCode]Word Pattern

题目描述:Given a pattern and a string str, find if str follows the same pattern.Examples:pattern = "abba", str = "dog cat cat dog" should return true. pattern = "abba", str = "dog cat cat fish" should...

View Article


Image may be NSFW.
Clik here to view.

[LeetCode]Unique Paths

题目描述: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 robot is trying to reach the...

View Article

[LeetCode]Nim Game

题目描述:You are playing the following Nim Game with your friend: There is a heap of stones on the table, each time one of you take turns to remove 1 to 3 stones. The one who removes the last stone will be...

View Article

[LeetCode]Find Median from Data Stream

题目描述:Median is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle value.Examples: [2,3,4] , the median...

View Article


[LeetCode]Serialize and Deserialize Binary Tree

题目描述:Serialization is the process of converting a data structure or object into a sequence of bits so that it can be stored in a file or memory buffer, or transmitted across a network connection link...

View Article

[LeetCode]Binary Tree Maximum Path Sum

题目描述:Given 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 connections. The...

View Article

[LeetCode]Bulls and Cows

题目描述:You are playing the following Bulls and Cows game with your friend: You write a 4-digit secret number and ask your friend to guess it, each time your friend guesses a number, you give a hint, the...

View Article


[LeetCode]Longest Increasing Subsequence

题目描述:Given 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, 101],...

View Article


[LeetCode]Remove Invalid Parentheses

题目描述:Remove the minimum number of invalid parentheses in order to make the input string valid. Return all possible results.Note: The input string may contain letters other than the parentheses ( and...

View Article

[LeetCode]Range Sum Query - Immutable

题目描述:Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive.Example: Given nums = [-2, 0, 3, -5, 2, -1] sumRange(0, 2) -> 1 sumRange(2, 5) -> -1...

View Article

Image may be NSFW.
Clik here to view.

[LeetCode]Range Sum Query 2D - Immutable

题目描述:Given a 2D matrix, find the sum of the elements inside the rectangle defined by (row1, col1), (row2, col2).The above rectangle (with the red border) is defined by (row1, col1) = (2, 1) and (row2,...

View Article

[LeetCode]Additive Number

题目描述:Additive number is a positive integer whose digits can form additive sequence.A valid additive sequence should contain at least three numbers. Except for the first two numbers, each subsequent...

View Article


[LeetCode]Range Sum Query - Mutable

题目描述:Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive.The update(i, val) function modifies nums by updating the element at index i to val.Example:...

View Article

[LeetCode]Best Time to Buy and Sell Stock with Cooldown

题目描述:Say you have an array for which the i-th element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, buy...

View Article


[LeetCode]Minimum Height Trees

题目描述:For a undirected graph with tree characteristics, we can choose any node as the root. The result graph is then a rooted tree. Among all possible rooted trees, those with minimum height are called...

View Article

[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...

View Article


[LeetCode]Burst Balloons

题目描述:Given n balloons, indexed from 0 to n-1. Each balloon is painted with a number on it represented by array nums. You are asked to burst all the balloons. If you burst balloon i you will get...

View Article

[LeetCode]Super Ugly Number

题目描述: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 example, [1, 2, 4, 7, 8, 13, 14,...

View Article

[LeetCode]Count of Smaller Numbers After Self

题目描述:You are given an integer array nums and you have to return a new counts array. The counts array has the property where counts[i] is the number of smaller elements to the right of...

View Article
Browsing all 559 articles
Browse latest View live