[Leetcode] Max Area of Island 最大岛屿面积

2019-02-01
阅读 2 分钟
2.5k
Given a non-empty 2D array grid of 0's and 1's, an island is a group of 1's (representing land) connected 4-directionally (horizontal or vertical.) You may assume all four edges of the grid are surrounded by water. Find the maximum area of an island in the given 2D array. (If there is no island, ...

[Leetcode] Cheapest Flights Within K Stops K次转机最便宜机票

2019-01-24
阅读 2 分钟
1.7k
There are n cities connected by m flights. Each fight starts from city u and arrives at v with a price w.Now given all the cities and flights, together with starting city src and the destination dst, your task is to find the cheapest price from src to dst with up to k stops. If there is no such r...

[Leetcode] Evaluate Division 计算除法

2018-12-05
阅读 5 分钟
2.2k
Equations are given in the format A / B = k, where A and B are variables represented as strings, and k is a real number (floating point number). Given some queries, return the answers. If the answer does not exist, return -1.0.Example:Given a / b = 2.0, b / c = 3.0. queries are: a / c = ?, b / a ...

[Leetcode] Bus Routes 公交线路

2018-11-06
阅读 3 分钟
2k
We have a list of bus routes. Each routes[i] is a bus route that the i-th bus repeats forever. For example if routes[0] = [1, 5, 7]`, this means that the first bus (0-th indexed) travels in the sequence 1->5->7->1->5->7->1->... forever.We start at bus stop S (initially not on...

[Leetcode] Matchsticks to Square 火柴拼方形

2018-02-21
阅读 2 分钟
3.2k
Remember the story of Little Match Girl? By now, you know exactly whatmatchsticks the little match girl has, please find out a way you canmake one square by using up all those matchsticks. You should notbreak any stick, but you can link them up, and each matchstick must beused exactly one time.Yo...

[Leetcode] Repeated Substring Pattern 重复子串格式

2018-02-20
阅读 2 分钟
2.9k
Given a non-empty string check if it can be constructed by taking asubstring of it and appending multiple copies of the substringtogether. You may assume the given string consists of lowercaseEnglish letters only and its length will not exceed 10000.Example: Input: "abab" Output: TrueExplanation:...

[Leetcode] Unique Substrings in Wraparound String 循环字符串中的唯一子串

2018-02-20
阅读 3 分钟
2.6k
Consider the string s to be the infinite wraparound string of"abcdefghijklmnopqrstuvwxyz", so s will look like this:"...zabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcd....".Now we have another string p. Your job is to find out how many uniquenon-empty substrings of p are present in s. I...

[Algo] Constant Time Random Picker 获取集合内随机元素

2015-11-08
阅读 2 分钟
3.2k
要求O(1)时间查询和删除,则想到哈希表,其他的数据结构都要遍历一遍才行。但是getRandom这功能有要求我们必须保持内容的有序,这样我们才能通过随机数的方法得到随机的某个元素。这里我们可以用数组、链表或者树保持有序,但是链表得到第n个元素要O(N)的时间,而树也要logN时间,所以不适合,只有数组。用数组的技巧在...

[Leetcode] Binary Tree Longest Consecutive Sequence 二叉搜索树最长序列

2015-11-06
阅读 2 分钟
11.4k
Given a binary tree, find the length of the longest consecutive sequence path. The path refers to any sequence of nodes from some starting node to any node in the tree along the parent-child connections. The longest consecutive path need to be from parent to child (cannot be the reverse). For exa...

[Algo] Maximum Expression Value 表达式最大值

2015-11-02
阅读 6 分钟
5.8k
给定一个整数数组,要求在数字之间任意添加乘号,加号和括号,使得最后表达式结果最大。比如1121,最大值为(1+1)*(2+1),所有数字都是正数。

[Algo] Parse XML Tree 解析XML文件

2015-11-01
阅读 3 分钟
3.3k
现在有一个Tokenizer,返回的Token都是XML标签或者内容,比如(open, html)(inner, hello)(close, html)表示<html>hello</html>,每一个括号及其内容是一个Token,请问如何表示这个XML文件。

[Algo] Install Dependencies 安装依赖

2015-10-29
阅读 3 分钟
3.2k
给定软件之间安装的依赖关系,用一个二维数组表示,第一维表示依赖的序号,第二维表示依赖关系,比如要先装deps[0][0],才能装deps[0][1]。安装时,要尽可能先安装依赖个数少的软件。求安装顺序。

[Leetcode] Repeated DNA Sequences 重复DNA序列

2015-10-29
阅读 3 分钟
9.2k
All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACGAATTCCG". When studying DNA, it is sometimes useful to identify repeated sequences within the DNA. Write a function to find all the 10-letter-long sequences (substrings) that occur more than once in a D...

[Leetcode] Minimum Size Subarray Sum 最短子串和

2015-10-29
阅读 2 分钟
7.4k
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,2,4,3] and s = 7, the subarray [4,3] has the minimal length under the problem constraint.

[Leetcode] Walls and Gates 墙与门

2015-10-26
阅读 3 分钟
12.3k
You are given a m x n 2D grid initialized with these three possible values. -1 - A wall or an obstacle. 0 - A gate. INF - Infinity means an empty room. We use the value 231 - 1 = 2147483647 to represent INF as you may assume that the distance to a gate is less than 2147483647. Fill each empty roo...

[Leetcode] Shortest Word Distance 最短单词间距

2015-10-26
阅读 4 分钟
15.4k
Given a list of words and two words word1 and word2, return the shortest distance between these two words in the list. For example, Assume that words = ["practice", "makes", "perfect", "coding", "makes"]. Given word1 = “coding”, word2 = “practice”, return 3. Given word1 = "makes", word2 = "coding...

[Leetcode] One Edit Distance 编辑距离为一

2015-10-26
阅读 2 分钟
13.3k
Given two strings S and T, determine if they are both one edit distance apart.

[Leetcode] Max Points on a Line 线上最大点数

2015-10-25
阅读 2 分钟
5.7k
Given n points on a 2D plane, find the maximum number of points that lie on the same straight line.

[Leetcode] Regular Expression Matching 正则表达式匹配

2015-10-25
阅读 3 分钟
8.2k
Implement regular expression matching with support for '.' and'*'. '.' Matches any single character. '*' Matches zero or more of the preceding element. The matching should cover the entire input string (not partial). The function prototype should be: {代码...} Some examples: {代码...}

[Leetcode] Paint House 房子涂色

2015-10-25
阅读 3 分钟
12.8k
There are a row of n houses, each house can be painted with one of the three colors: red, blue or green. The cost of painting each house with a certain color is different. You have to paint all the houses such that no two adjacent houses have the same color. The cost of painting each house with a...

[Leetcode] Sliding Window Maximum 滑动窗口最大值

2015-10-25
阅读 3 分钟
18.6k
Given an array nums, there is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the k numbers in the window. Each time the sliding window moves right by one position. For example, Given nums = [1,3,-1,-3,5,3,6,7], and k = 3. {代码...} T...

[Leetcode] Divide Two Integers 整数整除

2015-10-25
阅读 2 分钟
8.5k
Divide two integers without using multiplication, division and mod operator. If it is overflow, return MAX_INT.

[Leetcode] Excel Sheet Column Title Number Conversion Excel列值转换

2015-10-25
阅读 2 分钟
4.4k
Related to question Excel Sheet Column Title Given a column title as appear in an Excel sheet, return its corresponding column number. For example: {代码...}

[Leetcode] Substring with Concatenation of All Words 单词组合子字符串

2015-10-25
阅读 3 分钟
3.6k
You are given a string, s, and a list of words, words, that are all of the same length. Find all starting indices of substring(s) in s that is a concatenation of each word in words exactly once and without any intervening characters. For example, given: s: "barfoothefoobarman" words: ["foo", "bar...

[Algo] Eight Puzzle Game 九宫格游戏

2015-10-24
阅读 4 分钟
3.3k
九宫格游戏,给定最终状态如下,再给出一个初始状态,0代表空位,相邻的格子中的方块可以和0互换位置,求初始状态到最终状态的最小步数。 {代码...}

[Leetcode] Best Meeting Point 最佳见面点

2015-10-23
阅读 2 分钟
13.4k
A group of two or more people wants to meet and minimize the total travel distance. You are given a 2D grid of values 0 or 1, where each 1 marks the home of someone in the group. The distance is calculated using Manhattan Distance, where distance(p1, p2) = |p2.x - p1.x| + |p2.y - p1.y|. For examp...

[Leetcode] Meeting Rooms 会议室

2015-10-23
阅读 3 分钟
18.8k
Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si < ei), determine if a person could attend all meetings. For example, Given [[0, 30],[5, 10],[15, 20]], return false.

[Algo] Longest Descending Path 滑雪问题

2015-10-22
阅读 2 分钟
4.1k
给出一个矩阵,求矩阵中从某个点开始,最长的下降路径。路径可以走上下左右四个方向。求最长路径的长度。 {代码...} 其中一条最长路径是8 7 6 5 1

[Algo] Print Matrix Diagonal 对角打印

2015-10-22
阅读 1 分钟
2.2k
Print Matrix Diagonal Print the matrix in diagonal way. For example: {代码...} Print: {代码...} 双重循环 复杂度 时间 O(NM) 空间 O(1) 思路 总共需要打印的层数,是长度加宽度减去一。关键在于内层的row = i - j,而col = j。 代码 {代码...}

[Leetcode] Multiply String and Big Interger 大数乘法加法减法

2015-10-22
阅读 5 分钟
6.8k
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.