From 7a7d3f20b2969469e2f5d720200bf9a7dfd764d0 Mon Sep 17 00:00:00 2001
From: yanglbme 实现一个算法,确定一个字符串 Implement an algorithm to determine if a string has all unique characters. What if you cannot use additional data structures? Example 1: 给定两个字符串 Given two strings,write a method to decide if one is a permutation of the other. Given two strings,write a method to decide if one is a permutation of the other. Example 1: Example 2: Note: URL化。编写一种方法,将字符串中的空格全部替换为 Write a method to replace all spaces in a string with '%20'. You may assume that the string has sufficient space at the end to hold the additional characters,and that you are given the "true" length of the string. (Note: If implementing in Java,please use a character array so that you can perform this operation in place.) Write a method to replace all spaces in a string with '%20'. You may assume that the string has sufficient space at the end to hold the additional characters,and that you are given the "true" length of the string. (Note: If implementing in Java,please use a character array so that you can perform this operation in place.) Example 1: Example 2: Note: 给定一个字符串,编写一个函数判定其是否为某个回文串的排列之一。 Given a string, write a function to check if it is a permutation of a palin drome. A palindrome is a word or phrase that is the same forwards and backwards. A permutation is a rearrangement of letters. The palindrome does not need to be limited to just dictionary words. Given a string, write a function to check if it is a permutation of a palin drome. A palindrome is a word or phrase that is the same forwards and backwards. A permutation is a rearrangement of letters. The palindrome does not need to be limited to just dictionary words. Example1: 字符串有三种编辑操作:插入一个字符、删除一个字符或者替换一个字符。 给定两个字符串,编写一个函数判定它们是否只需要一次(或者零次)编辑。 There are three types of edits that can be performed on strings: insert a character, remove a character, or replace a character. Given two strings, write a function to check if they are one edit (or zero edits) away. Example 1: Example 2: 字符串压缩。利用字符重复出现的次数,编写一种方法,实现基本的字符串压缩功能。比如,字符串 Implement a method to perform basic string compression using the counts of repeated characters. For example, the string aabcccccaaa would become a2blc5a3. If the "compressed" string would not become smaller than the original string, your method should return the original string. You can assume the string has only uppercase and lowercase letters (a - z). Implement a method to perform basic string compression using the counts of repeated characters. For example, the string aabcccccaaa would become a2blc5a3. If the "compressed" string would not become smaller than the original string, your method should return the original string. You can assume the string has only uppercase and lowercase letters (a - z). Example 1: Example 2: 给定一幅由N × N矩阵表示的图像,其中每个像素的大小为4字节,编写一种方法,将图像旋转90度。 Given an image represented by an N x N matrix, where each pixel in the image is 4 bytes, write a method to rotate the image by 90 degrees. Can you do this in place? Given an image represented by an N x N matrix, where each pixel in the image is 4 bytes, write a method to rotate the image by 90 degrees. Can you do this in place? Example 1: Example 2: 编写一种算法,若M × N矩阵中某个元素为0,则将其所在的行与列清零。 Write an algorithm such that if an element in an MxN matrix is 0, its entire row and column are set to 0. Write an algorithm such that if an element in an MxN matrix is 0, its entire row and column are set to 0. Example 1: Example 2: 字符串轮转。给定两个字符串 Given two strings, Given two strings, Example 1: Example 2: Note: 编写代码,移除未排序链表中的重复节点。保留最开始出现的节点。 如果不得使用临时缓冲区,该怎么解决? Write code to remove duplicates from an unsorted linked list. Example1: Example2: Follow Up: How would you solve this problem if a temporary buffer is not allowed? 实现一种算法,找出单向链表中倒数第 k 个节点。返回该节点的值。 给定的 k 保证是有效的。 Implement an algorithm to find the kth to last element of a singly linked list. Return the value of the element. Implement an algorithm to find the kth to last element of a singly linked list. Return the value of the element. Note: This problem is slightly different from the original one in the book. Example: Note: k is always valid. 实现一种算法,删除单向链表中间的某个节点(除了第一个和最后一个节点,不一定是中间节点),假定你只能访问该节点。 Implement an algorithm to delete a node in the middle (i.e., any node but the first and last node, not necessarily the exact middle) of a singly linked list, given only access to that node. Implement an algorithm to delete a node in the middle (i.e., any node but the first and last node, not necessarily the exact middle) of a singly linked list, given only access to that node. Example: 编写程序以 x 为基准分割链表,使得所有小于 x 的节点排在大于或等于 x 的节点之前。如果链表中包含 x,x 只需出现在小于 x 的元素之后(如下所示)。分割元素 x 只需处于“右半部分”即可,其不需要被置于左右两部分之间。 Write code to partition a linked list around a value x, such that all nodes less than x come before all nodes greater than or equal to x. If x is contained within the list, the values of x only need to be after the elements less than x (see below). The partition element x can appear anywhere in the "right partition"; it does not need to appear between the left and right partitions. Write code to partition a linked list around a value x, such that all nodes less than x come before all nodes greater than or equal to x. If x is contained within the list, the values of x only need to be after the elements less than x (see below). The partition element x can appear anywhere in the "right partition"; it does not need to appear between the left and right partitions. Example: 给定两个用链表表示的整数,每个节点包含一个数位。 这些数位是反向存放的,也就是个位排在链表首部。 You have two numbers represented by a linked list, where each node contains a single digit. The digits are stored in reverse order, such that the 1's digit is at the head of the list. Write a function that adds the two numbers and returns the sum as a linked list. You have two numbers represented by a linked list, where each node contains a single digit. The digits are stored in reverse order, such that the 1's digit is at the head of the list. Write a function that adds the two numbers and returns the sum as a linked list. Example: Follow Up: Suppose the digits are stored in forward order. Repeat the above problem. Example: 编写一个函数,检查输入的链表是否是回文的。 进阶: Implement a function to check if a linked list is a palindrome. Implement a function to check if a linked list is a palindrome. Example 1: Example 2: Follow up: 给定两个(单向)链表,判定它们是否相交并返回交点。请注意相交的定义基于节点的引用,而不是基于节点的值。换句话说,如果一个链表的第k个节点与另一个链表的第j个节点是同一节点(引用完全相同),则这两个链表相交。 示例 1:
-> "*You help the developer community practice for interviews, and there is nothing better we could ask for.*" -- [Alan Yessenbayev](https://opencollective.com/alan-yessenbayev)
+> "_You help the developer community practice for interviews, and there is nothing better we could ask for._" -- [Alan Yessenbayev](https://opencollective.com/alan-yessenbayev)
## 许可证
知识共享 版权归属-相同方式共享 4.0 国际 公共许可证
-
\ No newline at end of file
+
diff --git a/README_EN.md b/README_EN.md
index 0725ac66e9ae9..3043f0ecfa29e 100644
--- a/README_EN.md
+++ b/README_EN.md
@@ -28,8 +28,8 @@ Complete solutions to [LeetCode](https://leetcode-cn.com/problemset/all/), [LCOF
## Solutions
1. [LeetCode](/solution/README_EN.md)
-1. [LCOF: *Coding Interviews, 2nd Edition*](/lcof/README_EN.md)
-1. [LCCI: *Cracking the Coding Interview, 6th Edition*](/lcci/README_EN.md)
+1. [LCOF: _Coding Interviews, 2nd Edition_](/lcof/README_EN.md)
+1. [LCCI: _Cracking the Coding Interview, 6th Edition_](/lcci/README_EN.md)
## Basic Algorithms
@@ -54,7 +54,6 @@ Complete solutions to [LeetCode](https://leetcode-cn.com/problemset/all/), [LCOF
1. [Lowest Common Ancestor of a Binary Tree](/solution/0200-0299/0236.Lowest%20Common%20Ancestor%20of%20a%20Binary%20Tree/README_EN.md)
1. [Lowest Common Ancestor of a Binary Search Tree](/solution/0200-0299/0235.Lowest%20Common%20Ancestor%20of%20a%20Binary%20Search%20Tree/README_EN.md)
-
### Math
1. [Set Mismatch](/solution/0600-0699/0645.Set%20Mismatch/README_EN.md)
@@ -65,7 +64,6 @@ Complete solutions to [LeetCode](https://leetcode-cn.com/problemset/all/), [LCOF
### Misc
-
## Maintainer
[Yang Libin](https://github.com/yanglbme): Creator of [@Doocs](https://github.com/doocs) technical community; member of [@TheAlgorithms](https://github.com/TheAlgorithms) organization.
@@ -89,7 +87,7 @@ You can also contribute to [doocs/leetcode](https://github.com/doocs/leetcode) u
## Contributors
-This project exists thanks to all the people who contribute.
+This project exists thanks to all the people who contribute.
@@ -101,11 +99,10 @@ Thank you to all our backers and sponsors!
-
-> "*You help the developer community practice for interviews, and there is nothing better we could ask for.*" -- [Alan Yessenbayev](https://opencollective.com/alan-yessenbayev)
+> "_You help the developer community practice for interviews, and there is nothing better we could ask for._" -- [Alan Yessenbayev](https://opencollective.com/alan-yessenbayev)
## License
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.
-
\ No newline at end of file
+
diff --git a/basic/README.md b/basic/README.md
index 79ee9be29acc5..8c967d74817e9 100644
--- a/basic/README.md
+++ b/basic/README.md
@@ -5,4 +5,4 @@
- [冒泡排序](./sorting/BubbleSort/README.md)
- [插入排序](./sorting/InsertionSort/README.md)
- [归并排序](./sorting/MergeSort/README.md)
-- [快速排序](./sorting/QuickSort/README.md)
\ No newline at end of file
+- [快速排序](./sorting/QuickSort/README.md)
diff --git a/basic/README_EN.md b/basic/README_EN.md
index 21374108453f2..4a0a0af8a1d68 100644
--- a/basic/README_EN.md
+++ b/basic/README_EN.md
@@ -5,4 +5,4 @@
- [Bubble Sort](./sorting/BubbleSort/README.md)
- [Insertion Sort](./sorting/InsertionSort/README.md)
- [Merge Sort](./sorting/MergeSort/README.md)
-- [Quick Sort](./sorting/QuickSort/README.md)
\ No newline at end of file
+- [Quick Sort](./sorting/QuickSort/README.md)
diff --git a/basic/sorting/BubbleSort/README.md b/basic/sorting/BubbleSort/README.md
index 72023f532e83a..3208134ce91a8 100644
--- a/basic/sorting/BubbleSort/README.md
+++ b/basic/sorting/BubbleSort/README.md
@@ -58,4 +58,4 @@ public class BubbleSort {
因此,时间复杂度是 O(n²),这是一种稳定的排序算法。
-> 稳定是指,两个相等的数,在排序过后,相对位置保持不变。
\ No newline at end of file
+> 稳定是指,两个相等的数,在排序过后,相对位置保持不变。
diff --git a/basic/sorting/MergeSort/README.md b/basic/sorting/MergeSort/README.md
index d7a739bd895b5..5c826b9d3796c 100644
--- a/basic/sorting/MergeSort/README.md
+++ b/basic/sorting/MergeSort/README.md
@@ -70,4 +70,4 @@ public class MergeSort {
由于合并 n 个元素需要分配一个大小为 n 的额外数组,所以空间复杂度为 O(n)。
-这是一种稳定的排序算法。
\ No newline at end of file
+这是一种稳定的排序算法。
diff --git a/basic/sorting/QuickSort/README.md b/basic/sorting/QuickSort/README.md
index 11b282271d4be..ba9ac23ef297f 100644
--- a/basic/sorting/QuickSort/README.md
+++ b/basic/sorting/QuickSort/README.md
@@ -1,4 +1,3 @@
-
# 快速排序
快速排序也采用了分治的思想:把原始的数组筛选成较小和较大的两个子数组,然后递归地排序两个子数组。
@@ -68,4 +67,4 @@ public class QuickSort {
但是,如果每次在选择基准值的时候,都不幸地选择了子数组里的最大或最小值。即每次把把数组分成了两个更小长度的数组,其中一个长度为 1,另一个的长度是子数组的长度减 1。这样的算法复杂度变成 O(n²)。
-和归并排序不同,快速排序在每次递归的过程中,只需要开辟 O(1) 的存储空间来完成操作来实现对数组的修改;而递归次数为 logn,所以它的整体空间复杂度完全取决于压堆栈的次数。
\ No newline at end of file
+和归并排序不同,快速排序在每次递归的过程中,只需要开辟 O(1) 的存储空间来完成操作来实现对数组的修改;而递归次数为 logn,所以它的整体空间复杂度完全取决于压堆栈的次数。
diff --git a/basic/summary.md b/basic/summary.md
index ed536e82a946a..89d5ed56be31c 100644
--- a/basic/summary.md
+++ b/basic/summary.md
@@ -1,6 +1,6 @@
- 基础算法通关
- - 常见的排序算法
- - [冒泡排序](/basic/sorting/BubbleSort/README.md)
- - [插入排序](/basic/sorting/InsertionSort/README.md)
- - [归并排序](/basic/sorting/MergeSort/README.md)
- - [快速排序](/basic/sorting/QuickSort/README.md)
\ No newline at end of file
+ - 常见的排序算法
+ - [冒泡排序](/basic/sorting/BubbleSort/README.md)
+ - [插入排序](/basic/sorting/InsertionSort/README.md)
+ - [归并排序](/basic/sorting/MergeSort/README.md)
+ - [快速排序](/basic/sorting/QuickSort/README.md)
diff --git a/lcci/01.01.Is Unique/README.md b/lcci/01.01.Is Unique/README.md
index 19664d7699e6d..3bf28d5b80943 100644
--- a/lcci/01.01.Is Unique/README.md
+++ b/lcci/01.01.Is Unique/README.md
@@ -3,6 +3,7 @@
[English Version](/lcci/01.01.Is%20Unique/README_EN.md)
## 题目描述
+
s
的所有字符是否全都不同。0 <= len(s) <= 100
0 <= len(s) <= 100
s1
和 s2
,请编写一个程序,确定其中一个字符串的字符重新排列后,能否变成另一个字符串。0 <= len(s2) <= 100
Input:
-
-
s1
= "abc", s2
= "bca"
@@ -19,12 +16,8 @@
Input:
-
-
s1
= "abc", s2
= "bad"
@@ -33,20 +26,14 @@
-
-
-
## Solutions
-
### **Python3**
@@ -75,8 +62,9 @@ class Solution {
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/lcci/01.03.String to URL/README.md b/lcci/01.03.String to URL/README.md
index 34904733fbc63..63b5f66b1ff66 100644
--- a/lcci/01.03.String to URL/README.md
+++ b/lcci/01.03.String to URL/README.md
@@ -1,8 +1,9 @@
-# [面试题 01.03. URL化](https://leetcode-cn.com/problems/string-to-url-lcci)
+# [面试题 01.03. URL 化](https://leetcode-cn.com/problems/string-to-url-lcci)
[English Version](/lcci/01.03.String%20to%20URL/README_EN.md)
## 题目描述
+
0 <= len(s1) <= 100
0 <= len(s2) <= 100
%20
。假定该字符串尾部有足够的空间存放新增字符,并且知道字符串的“真实”长度。(注:用Java
实现的话,请使用字符数组实现,以便直接在数组上操作。)
Input: "Mr John Smith ", 13
@@ -23,12 +20,8 @@ The missing numbers are [5,6,8,...], hence the third missing number is 8.
-
-
Input: " ", 5
@@ -37,26 +30,16 @@ The missing numbers are [5,6,8,...], hence the third missing number is 8.
-
-
-
-
-
## Solutions
-
### **Python3**
@@ -90,8 +73,9 @@ class Solution {
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/lcci/01.04.Palindrome Permutation/README.md b/lcci/01.04.Palindrome Permutation/README.md
index 5e2166f976fa0..0e297d35bdd99 100644
--- a/lcci/01.04.Palindrome Permutation/README.md
+++ b/lcci/01.04.Palindrome Permutation/README.md
@@ -3,6 +3,7 @@
[English Version](/lcci/01.04.Palindrome%20Permutation/README_EN.md)
## 题目描述
+
0 <= S.length <= 500000
Input: "tactcoa"
@@ -25,7 +20,6 @@
## Solutions
-
### **Python3**
@@ -75,8 +69,9 @@ class Solution {
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/lcci/01.05.One Away/README.md b/lcci/01.05.One Away/README.md
index 9dcf342160089..1dbca070bef9e 100644
--- a/lcci/01.05.One Away/README.md
+++ b/lcci/01.05.One Away/README.md
@@ -3,6 +3,7 @@
[English Version](/lcci/01.05.One%20Away/README_EN.md)
## 题目描述
+
-
## 解法
+
+
遍历两个字符串,逐个字符比较判断。
### **Python3**
+
```python
@@ -53,6 +56,7 @@ class Solution:
```
### **Java**
+
```java
@@ -80,8 +84,9 @@ class Solution {
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/lcci/01.05.One Away/README_EN.md b/lcci/01.05.One Away/README_EN.md
index 106e77685a38a..719353deadaea 100644
--- a/lcci/01.05.One Away/README_EN.md
+++ b/lcci/01.05.One Away/README_EN.md
@@ -3,6 +3,7 @@
[中文文档](/lcci/01.05.One%20Away/README.md)
## Description
+
Input:
@@ -35,12 +34,8 @@ second = "pal"
-
-
-
## Solutions
-
### **Python3**
@@ -89,8 +84,9 @@ class Solution {
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/lcci/01.06.Compress String/README.md b/lcci/01.06.Compress String/README.md
index 1fb3207314bd6..a4705a433d59b 100644
--- a/lcci/01.06.Compress String/README.md
+++ b/lcci/01.06.Compress String/README.md
@@ -3,6 +3,7 @@
[English Version](/lcci/01.06.Compress%20String/README_EN.md)
## 题目描述
+
aabcccccaaa
会变为a2b1c5a3
。若“压缩”后的字符串没有变短,则返回原先的字符串。你可以假设字符串中只包含大小写英文字母(a至z)。
Input: "abbccd"
@@ -39,11 +34,8 @@ The compressed string is "a1b2c2d1", which is longer than the original
- `0 <= S.length <= 50000`
-
-
## Solutions
-
### **Python3**
@@ -90,8 +82,9 @@ class Solution {
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/lcci/01.07.Rotate Matrix/README.md b/lcci/01.07.Rotate Matrix/README.md
index 5e4ac01c15358..54dd01dd0435c 100644
--- a/lcci/01.07.Rotate Matrix/README.md
+++ b/lcci/01.07.Rotate Matrix/README.md
@@ -3,6 +3,7 @@
[English Version](/lcci/01.07.Rotate%20Matrix/README_EN.md)
## 题目描述
+
-
## 解法
+
原地旋转,i 的范围是 `[0, n/2)`,j 的范围是 `[i, n-1-i)`。
@@ -55,6 +56,7 @@
### **Python3**
+
```python
@@ -75,6 +77,7 @@ class Solution:
```
### **Java**
+
```java
@@ -95,8 +98,9 @@ class Solution {
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/lcci/01.07.Rotate Matrix/README_EN.md b/lcci/01.07.Rotate Matrix/README_EN.md
index 0332491567b97..82932f7f9867f 100644
--- a/lcci/01.07.Rotate Matrix/README_EN.md
+++ b/lcci/01.07.Rotate Matrix/README_EN.md
@@ -3,18 +3,13 @@
[中文文档](/lcci/01.07.Rotate%20Matrix/README.md)
## Description
-
Given matrix =
@@ -45,12 +40,8 @@ Rotate the matrix in place. It becomes:
-
-
Given matrix =
@@ -85,12 +76,8 @@ Rotate the matrix in place. It becomes:
-
-
-
## Solutions
-
### **Python3**
@@ -132,8 +119,9 @@ class Solution {
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/lcci/01.08.Zero Matrix/README.md b/lcci/01.08.Zero Matrix/README.md
index f62ee752dc9dc..3cef9fd644bf6 100644
--- a/lcci/01.08.Zero Matrix/README.md
+++ b/lcci/01.08.Zero Matrix/README.md
@@ -3,6 +3,7 @@
[English Version](/lcci/01.08.Zero%20Matrix/README_EN.md)
## 题目描述
+
Input:
@@ -43,12 +38,8 @@
-
-
Input:
@@ -77,12 +68,8 @@
-
-
-
## Solutions
-
### **Python3**
@@ -100,15 +87,15 @@ class Solution:
if matrix[i][j] == 0:
zero_rows.add(i)
zero_cols.add(j)
-
+
for i in zero_rows:
for j in range(cols):
matrix[i][j] = 0
-
+
for j in zero_cols:
for i in range(rows):
matrix[i][j] = 0
-
+
return matrix
```
@@ -146,8 +133,9 @@ class Solution {
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/lcci/01.09.String Rotation/README.md b/lcci/01.09.String Rotation/README.md
index da482b56ac57e..cfc517474fe86 100644
--- a/lcci/01.09.String Rotation/README.md
+++ b/lcci/01.09.String Rotation/README.md
@@ -3,6 +3,7 @@
[English Version](/lcci/01.09.String%20Rotation/README_EN.md)
## 题目描述
+
s1
和s2
,请编写代码检查s2
是否为s1
旋转而成(比如,waterbottle
是erbottlewat
旋转后的字符串)。s1
and s2
, write code to check if s2
is a rotation of s1
(e.g.,"waterbottle" is a rotation of"erbottlewat"). Can you use only one call to the method that checks if one word is a substring of another?s1
and s2
, write code to check if s2
is a rotation of s1
(e.g.,"waterbottle" is a rotation of"erbottlewat"). Can you use only one call to the method that checks if one word is a substring of another?
Input: s1 = "waterbottle", s2 = "erbottlewat"
@@ -19,12 +16,8 @@
-
-
Input: s1 = "aa", "aba"
@@ -33,23 +26,14 @@
-
-
-
-
-
## Solutions
@@ -73,8 +57,9 @@ class Solution {
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/lcci/02.01.Remove Duplicate Node/README.md b/lcci/02.01.Remove Duplicate Node/README.md
index 78767407357db..159a271a25dd2 100644
--- a/lcci/02.01.Remove Duplicate Node/README.md
+++ b/lcci/02.01.Remove Duplicate Node/README.md
@@ -3,6 +3,7 @@
[English Version](/lcci/02.01.Remove%20Duplicate%20Node/README_EN.md)
## 题目描述
+
0 <= s1.length, s1.length <= 100000
Input: [1, 2, 3, 3, 2, 1]
@@ -16,7 +16,6 @@
-
@@ -32,23 +31,16 @@
-
+
Input: 1->2->3->4->5 和 k = 2
Output: 4
-
-
Input: the node c from the linked list a->b->c->d->e->f
@@ -23,12 +18,8 @@
-
-
-
## Solutions
-
### **Python3**
@@ -70,8 +61,9 @@ class Solution {
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/lcci/02.04.Partition List/README.md b/lcci/02.04.Partition List/README.md
index 21a432be4fb2f..d0f07d23e3563 100644
--- a/lcci/02.04.Partition List/README.md
+++ b/lcci/02.04.Partition List/README.md
@@ -3,6 +3,7 @@
[English Version](/lcci/02.04.Partition%20List/README_EN.md)
## 题目描述
+
Input: head = 3->5->8->5->10->2->1, x = 5
@@ -19,12 +16,8 @@
-
-
-
## Solutions
-
### **Python3**
@@ -94,8 +87,9 @@ class Solution {
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/lcci/02.05.Sum Lists/README.md b/lcci/02.05.Sum Lists/README.md
index 7064615920ee7..c56235b02ede9 100644
--- a/lcci/02.05.Sum Lists/README.md
+++ b/lcci/02.05.Sum Lists/README.md
@@ -3,6 +3,7 @@
[English Version](/lcci/02.05.Sum%20Lists/README_EN.md)
## 题目描述
+
Input: (7 -> 1 -> 6) + (5 -> 9 -> 2). That is, 617 + 295.
@@ -23,16 +18,10 @@
-
-
Input: (6 -> 1 -> 7) + (2 -> 9 -> 5). That is, 617 + 295.
@@ -41,12 +30,8 @@
-
-
-
## Solutions
-
### **Python3**
@@ -106,8 +91,9 @@ class Solution {
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/lcci/02.06.Palindrome Linked List/README.md b/lcci/02.06.Palindrome Linked List/README.md
index e1d3ef4b24ee3..9f342000a6f34 100644
--- a/lcci/02.06.Palindrome Linked List/README.md
+++ b/lcci/02.06.Palindrome Linked List/README.md
@@ -3,6 +3,7 @@
[English Version](/lcci/02.06.Palindrome%20Linked%20List/README_EN.md)
## 题目描述
+
你能否用 O(n) 时间复杂度和 O(1) 空间复杂度解决此题?
Input: 1->2
@@ -23,12 +18,8 @@
-
-
Input: 1->2->2->1
@@ -37,19 +28,14 @@
-
-
Could you do it in O(n) time and O(1) space?输入:intersectVal = 8, listA = [4,1,8,4,5], listB = [5,0,1,8,4,5], skipA = 2, skipB = 3
输出:Reference of the node with value = 8
输入解释:相交节点的值为 8 (注意,如果两个列表相交则不能为 0)。从各自的表头开始算起,链表 A 为 [4,1,8,4,5],链表 B 为 [5,0,1,8,4,5]。在 A 中,相交节点前有 2 个节点;在 B 中,相交节点前有 3 个节点。
示例 2:
输入:intersectVal = 2, listA = [0,9,1,2,4], listB = [3,2,4], skipA = 3, skipB = 1
输出:Reference of the node with value = 2
输入解释:相交节点的值为 2 (注意,如果两个列表相交则不能为 0)。从各自的表头开始算起,链表 A 为 [0,9,1,2,4],链表 B 为 [3,2,4]。在 A 中,相交节点前有 3 个节点;在 B 中,相交节点前有 1 个节点。
示例 3:
输入:intersectVal = 0, listA = [2,6,4], listB = [1,5], skipA = 3, skipB = 2
输出:null
输入解释:从各自的表头开始算起,链表 A 为 [2,6,4],链表 B 为 [1,5]。由于这两个链表不相交,所以 intersectVal 必须为 0,而 skipA 和 skipB 可以是任意值。
解释:这两个链表不相交,因此返回 null。
注意:
null
。Given two (singly) linked lists, determine if the two lists intersect. Return the inter secting node. Note that the intersection is defined based on reference, not value. That is, if the kth node of the first linked list is the exact same node (by reference) as the jth node of the second linked list, then they are intersecting.
- +Given two (singly) linked lists, determine if the two lists intersect. Return the inter secting node. Note that the intersection is defined based on reference, not value. That is, if the kth node of the first linked list is the exact same node (by reference) as the jth node of the second linked list, then they are intersecting.
Example 1:
- -Input: intersectVal = 8, listA = [4,1,8,4,5], listB = [5,0,1,8,4,5], skipA = 2, skipB = 3 @@ -19,12 +16,8 @@ Input Explanation: The intersected node's value is 8 (note that this must not be 0 if the two lists intersect). From the head of A, it reads as [4,1,8,4,5]. From the head of B, it reads as [5,0,1,8,4,5]. There are 2 nodes before the intersected node in A; There are 3 nodes before the intersected node in B.- -
Example 2:
- -Input: intersectVal = 2, listA = [0,9,1,2,4], listB = [3,2,4], skipA = 3, skipB = 1 @@ -33,12 +26,8 @@ Input Explanation: The intersected node's value is 2 (note that this must not be 0 if the two lists intersect). From the head of A, it reads as [0,9,1,2,4]. From the head of B, it reads as [3,2,4]. There are 3 nodes before the intersected node in A; There are 1 node before the intersected node in B.- -
Example 3:
- -Input: intersectVal = 0, listA = [2,6,4], listB = [1,5], skipA = 3, skipB = 2 @@ -49,7 +38,6 @@ Explanation: The two lists do not intersect, so return null.-
Notes:
- If the two linked lists have no intersection at all, returnnull
.
@@ -59,7 +47,6 @@
## Solutions
-
### **Python3**
@@ -142,8 +129,9 @@ public class Solution {
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/lcci/02.08.Linked List Cycle/README.md b/lcci/02.08.Linked List Cycle/README.md
index c029407e05d41..2e04e7dfb0ea5 100644
--- a/lcci/02.08.Linked List Cycle/README.md
+++ b/lcci/02.08.Linked List Cycle/README.md
@@ -3,16 +3,18 @@
[English Version](/lcci/02.08.Linked%20List%20Cycle/README_EN.md)
## 题目描述
+
给定一个有环链表,实现一个算法返回环路的开头节点。
有环链表的定义:在链表中某个节点的next元素指向在它前面出现过的节点,则表明该链表存在环路。
示例 1:
输入:head = [3,2,0,-4], pos = 1
输出:tail connects to node index 1
解释:链表中有一个环,其尾部连接到第二个节点。
示例 2:
输入:head = [1,2], pos = 0
输出:tail connects to node index 0
解释:链表中有一个环,其尾部连接到第一个节点。
示例 3:
输入:head = [1], pos = -1
输出:no cycle
解释:链表中没有环。
进阶:
你是否可以不用额外空间解决此题?
Given a circular linked list, implement an algorithm that returns the node at the beginning of the loop.
- +Given a circular linked list, implement an algorithm that returns the node at the beginning of the loop.
Circular linked list: A (corrupt) linked list in which a node's next pointer points to an earlier node, so as to make a loop in the linked list.
- -Example 1:
- -Input: head = [3,2,0,-4], pos = 1 Output: tail connects to node index 1- -
Example 2:
- -Input: head = [1,2], pos = 0 Output: tail connects to node index 0- -
Example 3:
- -Input: head = [1], pos = -1 Output: no cycle- -
Follow Up:
Can you solve it without using additional space?
三合一。描述如何只用一个数组来实现三个栈。
@@ -29,14 +30,16 @@ [null, null, null, null, 2, 1, -1, -1] - ## 解法 + + 二维数组解决;也可以使用一维数组,以下标 `0,3,6,..`、`1,4,7,..`、`2,5,8,..` 区分,一维数组最后三个元素记录每个栈的元素个数。 ### **Python3** + ```python @@ -69,6 +72,7 @@ class TripleInOne: ``` ### **Java** + ```java @@ -80,14 +84,14 @@ class TripleInOne { s = new int[stackSize * 3 + 3]; capacity = stackSize; } - + public void push(int stackNum, int value) { if (s[stackNum + 3 * capacity] < capacity) { s[s[stackNum + 3 * capacity] * 3 + stackNum] = value; ++s[stackNum + 3 * capacity]; } } - + public int pop(int stackNum) { if (isEmpty(stackNum)) { return -1; @@ -95,11 +99,11 @@ class TripleInOne { --s[stackNum + 3 * capacity]; return s[s[stackNum + 3 * capacity] * 3 + stackNum]; } - + public int peek(int stackNum) { return isEmpty(stackNum) ? -1 : s[(s[stackNum + 3 * capacity] - 1) * 3 + stackNum]; } - + public boolean isEmpty(int stackNum) { return s[stackNum + 3 * capacity] == 0; } @@ -116,8 +120,9 @@ class TripleInOne { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/03.01.Three in One/README_EN.md b/lcci/03.01.Three in One/README_EN.md index 2d77e29430e94..40ded4afb328f 100644 --- a/lcci/03.01.Three in One/README_EN.md +++ b/lcci/03.01.Three in One/README_EN.md @@ -3,22 +3,15 @@ [中文文档](/lcci/03.01.Three%20in%20One/README.md) ## Description -Describe how you could use a single array to implement three stacks.
- +Describe how you could use a single array to implement three stacks.
Yout should implement push(stackNum, value)
、pop(stackNum)
、isEmpty(stackNum)
、peek(stackNum)
methods. stackNum
is the index of the stack. value
is the value that pushed to the stack.
The constructor requires a stackSize
parameter, which represents the size of each stack.
Example1:
- -Input: @@ -35,12 +28,8 @@- -
Example2:
- -Input: @@ -55,12 +44,8 @@- - - ## Solutions - ### **Python3** @@ -105,14 +90,14 @@ class TripleInOne { s = new int[stackSize * 3 + 3]; capacity = stackSize; } - + public void push(int stackNum, int value) { if (s[stackNum + 3 * capacity] < capacity) { s[s[stackNum + 3 * capacity] * 3 + stackNum] = value; ++s[stackNum + 3 * capacity]; } } - + public int pop(int stackNum) { if (isEmpty(stackNum)) { return -1; @@ -120,11 +105,11 @@ class TripleInOne { --s[stackNum + 3 * capacity]; return s[s[stackNum + 3 * capacity] * 3 + stackNum]; } - + public int peek(int stackNum) { return isEmpty(stackNum) ? -1 : s[(s[stackNum + 3 * capacity] - 1) * 3 + stackNum]; } - + public boolean isEmpty(int stackNum) { return s[stackNum + 3 * capacity] == 0; } @@ -141,8 +126,9 @@ class TripleInOne { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/03.02.Min Stack/README.md b/lcci/03.02.Min Stack/README.md index 8d05969560198..aa0a010ca2972 100644 --- a/lcci/03.02.Min Stack/README.md +++ b/lcci/03.02.Min Stack/README.md @@ -3,17 +3,20 @@ [English Version](/lcci/03.02.Min%20Stack/README_EN.md) ## 题目描述 +
请设计一个栈,除了常规栈支持的pop与push函数以外,还支持min函数,该函数返回栈元素中的最小值。执行push、pop和min操作的时间复杂度必须为O(1)。
示例:
MinStack minStack = new MinStack();## 解法 + -利用辅助栈存放栈的最小元素。 +利用辅助栈存放栈的最小元素。 ### **Python3** + ```python @@ -51,6 +54,7 @@ class MinStack: ``` ### **Java** + ```java @@ -63,21 +67,21 @@ class MinStack { s1 = new Stack<>(); s2 = new Stack<>(); } - + public void push(int x) { s1.push(x); s2.push(s2.empty() || s2.peek() >= x ? x : s2.peek()); } - + public void pop() { s1.pop(); s2.pop(); } - + public int top() { return s1.peek(); } - + public int getMin() { return s2.empty() ? -1 : s2.peek(); } @@ -94,8 +98,9 @@ class MinStack { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/03.02.Min Stack/README_EN.md b/lcci/03.02.Min Stack/README_EN.md index 7bd358029b1a0..57fb34d7ede8f 100644 --- a/lcci/03.02.Min Stack/README_EN.md +++ b/lcci/03.02.Min Stack/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/lcci/03.02.Min%20Stack/README.md) ## Description -
minStack.push(-2);
minStack.push(0);
minStack.push(-3);
minStack.getMin(); --> 返回 -3.
minStack.pop();
minStack.top(); --> 返回 0.
minStack.getMin(); --> 返回 -2.
How would you design a stack which, in addition to push and pop, has a function min which returns the minimum element? Push, pop and min should all operate in 0(1) time.
- +How would you design a stack which, in addition to push and pop, has a function min which returns the minimum element? Push, pop and min should all operate in 0(1) time.
Example:
- -MinStack minStack = new MinStack(); @@ -29,12 +26,8 @@ minStack.top(); --> return 0. minStack.getMin(); --> return -2.- - - ## Solutions - ### **Python3** @@ -85,21 +78,21 @@ class MinStack { s1 = new Stack<>(); s2 = new Stack<>(); } - + public void push(int x) { s1.push(x); s2.push(s2.empty() || s2.peek() >= x ? x : s2.peek()); } - + public void pop() { s1.pop(); s2.pop(); } - + public int top() { return s1.peek(); } - + public int getMin() { return s2.empty() ? -1 : s2.peek(); } @@ -116,8 +109,9 @@ class MinStack { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/03.03.Stack of Plates/README.md b/lcci/03.03.Stack of Plates/README.md index 014c53aa032fd..11f4acacf2ce9 100644 --- a/lcci/03.03.Stack of Plates/README.md +++ b/lcci/03.03.Stack of Plates/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/03.03.Stack%20of%20Plates/README_EN.md) ## 题目描述 +
堆盘子。设想有一堆盘子,堆太高可能会倒下来。因此,在现实生活中,盘子堆到一定高度时,我们就会另外堆一堆盘子。请实现数据结构SetOfStacks
,模拟这种行为。SetOfStacks
应该由多个栈组成,并且在前一个栈填满时新建一个栈。此外,SetOfStacks.push()
和SetOfStacks.pop()
应该与普通栈的操作方法相同(也就是说,pop()返回的值,应该跟只有一个栈时的情况一样)。 进阶:实现一个popAt(int index)
方法,根据指定的子栈,执行pop操作。
Imagine a (literal) stack of plates. If the stack gets too high, it might topple. Therefore, in real life, we would likely start a new stack when the previous stack exceeds some threshold. Implement a data structure SetOfStacks
that mimics this. SetOfStacks
should be composed of several stacks and should create a new stack once the previous one exceeds capacity. SetOfStacks.push()
and SetOfStacks.pop()
should behave identically to a single stack (that is, pop()
should return the same values as it would if there were just a single stack). Follow Up: Implement a function popAt(int index)
which performs a pop operation on a specific sub-stack.
Imagine a (literal) stack of plates. If the stack gets too high, it might topple. Therefore, in real life, we would likely start a new stack when the previous stack exceeds some threshold. Implement a data structure SetOfStacks
that mimics this. SetOfStacks
should be composed of several stacks and should create a new stack once the previous one exceeds capacity. SetOfStacks.push()
and SetOfStacks.pop()
should behave identically to a single stack (that is, pop()
should return the same values as it would if there were just a single stack). Follow Up: Implement a function popAt(int index)
which performs a pop operation on a specific sub-stack.
You should delete the sub-stack when it becomes empty. pop
, popAt
should return -1 when there's no element to pop.
Example1:
- -Input: @@ -31,12 +26,8 @@- -
Example2:
- -Input: @@ -51,12 +42,8 @@- - - ## Solutions - ### **Python3** @@ -72,8 +59,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/03.04.Implement Queue using Stacks/README.md b/lcci/03.04.Implement Queue using Stacks/README.md index 47e331e30e931..c3ce9842b4c0d 100644 --- a/lcci/03.04.Implement Queue using Stacks/README.md +++ b/lcci/03.04.Implement Queue using Stacks/README.md @@ -3,11 +3,14 @@ [English Version](/lcci/03.04.Implement%20Queue%20using%20Stacks/README_EN.md) ## 题目描述 +
实现一个MyQueue类,该类用两个栈来实现一个队列。
示例:
MyQueue queue = new MyQueue();
queue.push(1);
queue.push(2);
queue.peek(); // 返回 1
queue.pop(); // 返回 1
queue.empty(); // 返回 false
说明:
push to top
, peek/pop from top
, size
和 is empty
操作是合法的。Implement a MyQueue class which implements a queue using two stacks.
- -Example:
- -MyQueue queue = new MyQueue(); @@ -29,32 +26,20 @@ queue.pop(); // return 1 queue.empty(); // return false- -
- -
Notes:
- -push to top
, peek/pop from top
, size
, and is empty
operations are valid.- - - ## Solutions - ### **Python3** @@ -124,12 +109,12 @@ class MyQueue { s1 = new Stack<>(); s2 = new Stack<>(); } - + /** Push element x to the back of queue. */ public void push(int x) { s1.push(x); } - + /** Removes the element from in front of queue and returns that element. */ public int pop() { if (s2.empty()) { @@ -139,7 +124,7 @@ class MyQueue { } return s2.pop(); } - + /** Get the front element. */ public int peek() { if (s2.empty()) { @@ -149,7 +134,7 @@ class MyQueue { } return s2.peek(); } - + /** Returns whether the queue is empty. */ public boolean empty() { return s1.empty() && s2.empty(); @@ -167,8 +152,9 @@ class MyQueue { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/03.05.Sort of Stacks/README.md b/lcci/03.05.Sort of Stacks/README.md index 6211150d22f7f..5fd0243eef6e5 100644 --- a/lcci/03.05.Sort of Stacks/README.md +++ b/lcci/03.05.Sort of Stacks/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/03.05.Sort%20of%20Stacks/README_EN.md) ## 题目描述 +
栈排序。 编写程序,对栈进行排序使最小元素位于栈顶。最多只能使用一个其他的临时栈存放数据,但不得将元素复制到别的数据结构(如数组)中。该栈支持如下操作:push
、pop
、peek
和 isEmpty
。当栈为空时,peek
返回 -1。
Write a program to sort a stack such that the smallest items are on the top. You can use an additional temporary stack, but you may not copy the elements into any other data structure (such as an array). The stack supports the following operations: push
, pop
, peek
, and isEmpty
. When the stack is empty, peek
should return -1.
Write a program to sort a stack such that the smallest items are on the top. You can use an additional temporary stack, but you may not copy the elements into any other data structure (such as an array). The stack supports the following operations: push
, pop
, peek
, and isEmpty
. When the stack is empty, peek
should return -1.
Example1:
- -Input: @@ -25,12 +22,8 @@- -
Example2:
- -Input: @@ -45,22 +38,14 @@- -
Note:
- -动物收容所。有家动物收容所只收容狗与猫,且严格遵守“先进先出”的原则。在收养该收容所的动物时,收养人只能收养所有动物中“最老”(由其进入收容所的时间长短而定)的动物,或者可以挑选猫或狗(同时必须收养此类动物中“最老”的)。换言之,收养人不能自由挑选想收养的对象。请创建适用于这个系统的数据结构,实现各种操作方法,比如enqueue
、dequeueAny
、dequeueDog
和dequeueCat
。允许使用Java内置的LinkedList数据结构。
An animal shelter, which holds only dogs and cats, operates on a strictly"first in, first out" basis. People must adopt either the"oldest" (based on arrival time) of all animals at the shelter, or they can select whether they would prefer a dog or a cat (and will receive the oldest animal of that type). They cannot select which specific animal they would like. Create the data structures to maintain this system and implement operations such as enqueue
, dequeueAny
, dequeueDog
, and dequeueCat
. You may use the built-in Linked list data structure.
An animal shelter, which holds only dogs and cats, operates on a strictly"first in, first out" basis. People must adopt either the"oldest" (based on arrival time) of all animals at the shelter, or they can select whether they would prefer a dog or a cat (and will receive the oldest animal of that type). They cannot select which specific animal they would like. Create the data structures to maintain this system and implement operations such as enqueue
, dequeueAny
, dequeueDog
, and dequeueCat
. You may use the built-in Linked list data structure.
enqueue
method has a animal
parameter, animal[0]
represents the number of the animal, animal[1]
represents the type of the animal, 0 for cat and 1 for dog.
dequeue*
method returns [animal number, animal type]
, if there's no animal that can be adopted, return [-1, -1]
.
Example1:
- -Input: @@ -33,12 +26,8 @@- -
Example2:
- -Input: @@ -53,22 +42,14 @@- -
Note:
- -节点间通路。给定有向图,设计一个算法,找出两个节点之间是否存在一条路径。
@@ -26,14 +27,14 @@Given a directed graph, design an algorithm to find out whether there is a route between two nodes.
- +Given a directed graph, design an algorithm to find out whether there is a route between two nodes.
Example1:
- -Input: n = 3, graph = [[0, 1], [0, 2], [1, 2], [1, 2]], start = 0, target = 2 @@ -19,12 +16,8 @@- -
Example2:
- -Input: n = 5, graph = [[0, 1], [0, 2], [0, 4], [0, 4], [0, 1], [1, 3], [1, 4], [1, 3], [2, 3], [3, 4]], start = 0, target = 4 @@ -33,24 +26,16 @@- -
Note:
- -0 <= n <= 100000
给定一个有序整数数组,元素各不相同且按升序排列,编写一个算法,创建一棵高度最小的二叉搜索树。
示例:给定有序数组: [-10,-3,0,5,9],## 解法 - + ### **Python3** + ```python @@ -20,6 +22,7 @@ ``` ### **Java** + ```java @@ -27,8 +30,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/04.02.Minimum Height Tree/README_EN.md b/lcci/04.02.Minimum Height Tree/README_EN.md index c8e5b5d266e5e..e37df1d4c56ef 100644 --- a/lcci/04.02.Minimum Height Tree/README_EN.md +++ b/lcci/04.02.Minimum Height Tree/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/lcci/04.02.Minimum%20Height%20Tree/README.md) ## Description -
一个可能的答案是:[0,-3,9,-10,null,5],它可以表示下面这个高度平衡二叉搜索树:
0
/ \
-3 9
/ /
-10 5
Given a sorted (increasing order) array with unique integer elements, write an algorithm to create a binary search tree with minimal height.
- +Given a sorted (increasing order) array with unique integer elements, write an algorithm to create a binary search tree with minimal height.
Example:
- -Given sorted array: [-10,-3,0,5,9], @@ -33,12 +30,8 @@ One possible answer is: [0,-3,9,-10,null,5],which represents the following tre- - - ## Solutions - ### **Python3** @@ -54,8 +47,9 @@ One possible answer is: [0,-3,9,-10,null,5],which represents the following tre ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/04.03.List of Depth/README.md b/lcci/04.03.List of Depth/README.md index 470c7277fc474..c8861174580ff 100644 --- a/lcci/04.03.List of Depth/README.md +++ b/lcci/04.03.List of Depth/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/04.03.List%20of%20Depth/README_EN.md) ## 题目描述 +
给定一棵二叉树,设计一个算法,创建含有某一深度上所有节点的链表(比如,若一棵树的深度为 D
,则会创建出 D
个链表)。返回一个包含所有深度的链表的数组。
Given a binary tree, design an algorithm which creates a linked list of all the nodes at each depth (e.g., if you have a tree with depth D, you'll have D linked lists). Return a array containing all the linked lists.
- +Given a binary tree, design an algorithm which creates a linked list of all the nodes at each depth (e.g., if you have a tree with depth D, you'll have D linked lists). Return a array containing all the linked lists.
- -
Example:
- -Input: [1,2,3,4,5,null,7,8] @@ -41,12 +36,8 @@- - - ## Solutions - ### **Python3** @@ -62,8 +53,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/04.04.Check Balance/README.md b/lcci/04.04.Check Balance/README.md index 07236b556a228..65e5f677b3a87 100644 --- a/lcci/04.04.Check Balance/README.md +++ b/lcci/04.04.Check Balance/README.md @@ -3,16 +3,20 @@ [English Version](/lcci/04.04.Check%20Balance/README_EN.md) ## 题目描述 +
实现一个函数,检查二叉树是否平衡。在这个问题中,平衡树的定义如下:任意一个节点,其两棵子树的高度差不超过 1。
给定二叉树 [3,9,20,null,null,15,7]示例 2:
3
/ \
9 20
/ \
15 7
返回 true 。
给定二叉树 [1,2,2,3,3,null,null,4,4]## 解法 + + 递归法。 ### **Python3** + ```python @@ -37,6 +41,7 @@ class Solution: ``` ### **Java** + ```java @@ -68,8 +73,9 @@ class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/04.04.Check Balance/README_EN.md b/lcci/04.04.Check Balance/README_EN.md index a9daa3059a9d0..1db241ff3357c 100644 --- a/lcci/04.04.Check Balance/README_EN.md +++ b/lcci/04.04.Check Balance/README_EN.md @@ -3,16 +3,13 @@ [中文文档](/lcci/04.04.Check%20Balance/README.md) ## Description -
1
/ \
2 2
/ \
3 3
/ \
4 4
返回 false 。
Implement a function to check if a binary tree is balanced. For the purposes of this question, a balanced tree is defined to be a tree such that the heights of the two subtrees of any node never differ by more than one.
- +Implement a function to check if a binary tree is balanced. For the purposes of this question, a balanced tree is defined to be a tree such that the heights of the two subtrees of any node never differ by more than one.
Example 1:
Given tree [3,9,20,null,null,15,7] @@ -29,12 +26,8 @@ Given tree [3,9,20,null,null,15,7] return true.- -
Example 2:
- -Given [1,2,2,3,3,null,null,4,4] @@ -55,16 +48,10 @@ Given [1,2,2,3,3,null,null,4,4] return false.- -
- - - ## Solutions - ### **Python3** @@ -121,8 +108,9 @@ class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/04.05.Legal Binary Search Tree/README.md b/lcci/04.05.Legal Binary Search Tree/README.md index 21b9e8fe2e59d..afbf1e786de10 100644 --- a/lcci/04.05.Legal Binary Search Tree/README.md +++ b/lcci/04.05.Legal Binary Search Tree/README.md @@ -3,16 +3,20 @@ [English Version](/lcci/04.05.Legal%20Binary%20Search%20Tree/README_EN.md) ## 题目描述 +
实现一个函数,检查一棵二叉树是否为二叉搜索树。
示例 1:输入:示例 2:
2
/ \
1 3
输出: true
输入:## 解法 + + 一棵合法的二叉搜索树,其中序遍历的结果应该升序排列。 ### **Python3** + ```python @@ -42,6 +46,7 @@ class Solution: ``` ### **Java** + ```java @@ -79,8 +84,9 @@ class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/04.05.Legal Binary Search Tree/README_EN.md b/lcci/04.05.Legal Binary Search Tree/README_EN.md index 96f782a02bc1b..e59cb8bab8a21 100644 --- a/lcci/04.05.Legal Binary Search Tree/README_EN.md +++ b/lcci/04.05.Legal Binary Search Tree/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/lcci/04.05.Legal%20Binary%20Search%20Tree/README.md) ## Description -
5
/ \
1 4
/ \
3 6
输出: false
解释: 输入为: [5,1,4,null,null,3,6]。
根节点的值为 5 ,但是其右子节点值为 4 。
Implement a function to check if a binary tree is a binary search tree.
- +Implement a function to check if a binary tree is a binary search tree.
Example 1:
- -Input: @@ -25,12 +22,8 @@- -
Example 2:
- -Input: @@ -51,12 +44,8 @@ the value of root node is 5, but its right child has value 4.- - - ## Solutions - ### **Python3** @@ -124,8 +113,9 @@ class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/04.06.Successor/README.md b/lcci/04.06.Successor/README.md index 4a501d6d0bce5..8193be99537ed 100644 --- a/lcci/04.06.Successor/README.md +++ b/lcci/04.06.Successor/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/04.06.Successor/README_EN.md) ## 题目描述 +
设计一个算法,找出二叉搜索树中指定节点的“下一个”节点(也即中序后继)。
@@ -32,14 +33,14 @@ 输出: null - ## 解法 - + ### **Python3** + ```python @@ -47,6 +48,7 @@ ``` ### **Java** + ```java @@ -54,8 +56,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/04.06.Successor/README_EN.md b/lcci/04.06.Successor/README_EN.md index d2441df2f52d3..f9fd091350e40 100644 --- a/lcci/04.06.Successor/README_EN.md +++ b/lcci/04.06.Successor/README_EN.md @@ -3,18 +3,13 @@ [中文文档](/lcci/04.06.Successor/README.md) ## Description -Write an algorithm to find the "next" node (i.e., in-order successor) of a given node in a binary search tree.
- +Write an algorithm to find the "next" node (i.e., in-order successor) of a given node in a binary search tree.
Return null
if there's no "next" node for the given node.
Example 1:
- -
Input: root = [2,1,3], p = 1
@@ -31,12 +26,8 @@
Output: 2
-
-
Example 2:
- -
Input: root = [5,3,6,2,4,null,null,1], p = 6
@@ -61,12 +52,8 @@
Output: null
-
-
-
## Solutions
-
### **Python3**
@@ -82,8 +69,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/lcci/04.08.First Common Ancestor/README.md b/lcci/04.08.First Common Ancestor/README.md
index 197fc8c85208b..a4f7bc1adc869 100644
--- a/lcci/04.08.First Common Ancestor/README.md
+++ b/lcci/04.08.First Common Ancestor/README.md
@@ -3,16 +3,18 @@
[English Version](/lcci/04.08.First%20Common%20Ancestor/README_EN.md)
## 题目描述
+
设计并实现一个算法,找出二叉树中某两个节点的第一个共同祖先。不得将其他的节点存储在另外的数据结构中。注意:这不一定是二叉搜索树。
例如,给定如下二叉树: root = [3,5,1,6,2,0,8,null,null,7,4]
3示例 1:
/ \
5 1
/ \ / \
6 2 0 8
/ \
7 4
输入: root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 1示例 2:
输入: 3
解释: 节点 5 和节点 1 的最近公共祖先是节点 3。
输入: root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 4说明:
输出: 5
解释: 节点 5 和节点 4 的最近公共祖先是节点 5。因为根据定义最近公共祖先节点可以为节点本身。
所有节点的值都是唯一的。## 解法 - + ### **Python3** + ```python @@ -33,6 +35,7 @@ class Solution: ``` ### **Java** + ```java @@ -58,8 +61,9 @@ class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/04.08.First Common Ancestor/README_EN.md b/lcci/04.08.First Common Ancestor/README_EN.md index c0591b2f6a27b..8dd1145bf3b71 100644 --- a/lcci/04.08.First Common Ancestor/README_EN.md +++ b/lcci/04.08.First Common Ancestor/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/lcci/04.08.First%20Common%20Ancestor/README.md) ## Description -
p、q 为不同节点且均存在于给定的二叉树中。
Design an algorithm and write code to find the first common ancestor of two nodes in a binary tree. Avoid storing additional nodes in a data structure. NOTE: This is not necessarily a binary search tree.
- +Design an algorithm and write code to find the first common ancestor of two nodes in a binary tree. Avoid storing additional nodes in a data structure. NOTE: This is not necessarily a binary search tree.
For example, Given the following tree: root = [3,5,1,6,2,0,8,null,null,7,4]
- -3 @@ -29,12 +26,8 @@- -
Example 1:
- -Input: root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 1 @@ -43,12 +36,8 @@ Explanation: The first common ancestor of node 5 and node 1 is node 3.- -
Example 2:
- -Input: root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 4 @@ -57,8 +46,6 @@ Explanation: The first common ancestor of node 5 and node 4 is node 5.- -
Notes:
从左向右遍历一个数组,通过不断将其中的元素插入树中可以逐步地生成一棵二叉搜索树。给定一个由不同节点组成的二叉树,输出所有可能生成此树的数组。
@@ -22,14 +23,14 @@ ] - ## 解法 - + ### **Python3** + ```python @@ -37,6 +38,7 @@ ``` ### **Java** + ```java @@ -44,8 +46,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/04.09.BST Sequences/README_EN.md b/lcci/04.09.BST Sequences/README_EN.md index 90252671811bd..0117940590e53 100644 --- a/lcci/04.09.BST Sequences/README_EN.md +++ b/lcci/04.09.BST Sequences/README_EN.md @@ -3,16 +3,13 @@ [中文文档](/lcci/04.09.BST%20Sequences/README.md) ## Description -A binary search tree was created by traversing through an array from left to right and inserting each element. Given a binary search tree with distinct elements, print all possible arrays that could have led to this tree.
- +A binary search tree was created by traversing through an array from left to right and inserting each element. Given a binary search tree with distinct elements, print all possible arrays that could have led to this tree.
Example:
Given the following tree:
2 @@ -23,12 +20,8 @@ Given the following tree:- -
Output:
- -[ @@ -41,12 +34,8 @@ Given the following tree:- - - ## Solutions - ### **Python3** @@ -62,8 +51,9 @@ Given the following tree: ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/04.10.Check SubTree/README.md b/lcci/04.10.Check SubTree/README.md index e5f692e3c02c8..4c2d42e7946da 100644 --- a/lcci/04.10.Check SubTree/README.md +++ b/lcci/04.10.Check SubTree/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/04.10.Check%20SubTree/README_EN.md) ## 题目描述 +
检查子树。你有两棵非常大的二叉树:T1,有几万个节点;T2,有几万个节点。设计一个算法,判断 T2 是否为 T1 的子树。
@@ -26,14 +27,16 @@T1 and T2 are two very large binary trees, with T1 much bigger than T2. Create an algorithm to determine if T2 is a subtree of T1.
- +T1 and T2 are two very large binary trees, with T1 much bigger than T2. Create an algorithm to determine if T2 is a subtree of T1.
A tree T2 is a subtree of T1 if there exists a node n in T1 such that the subtree of n is identical to T2. That is, if you cut off the tree at node n, the two trees would be identical.
- -Example1:
- -Input: t1 = [1, 2, 3], t2 = [2] @@ -23,12 +18,8 @@- -
Example2:
- -Input: t1 = [1, null, 2, 4], t2 = [3, 2] @@ -37,20 +28,14 @@- -
Note:
- -给定一棵二叉树,其中每个节点都含有一个整数数值(该值或正或负)。设计一个算法,打印节点数值总和等于某个给定值的所有路径的数量。注意,路径不一定非得从二叉树的根节点或叶节点开始或结束,但是其方向必须向下(只能从父节点指向子节点方向)。
@@ -29,16 +30,20 @@节点总数 <= 10000
You are given a binary tree in which each node contains an integer value (which might be positive or negative). Design an algorithm to count the number of paths that sum to a given value. The path does not need to start or end at the root or a leaf, but it must go downwards (traveling only from parent nodes to child nodes).
- +You are given a binary tree in which each node contains an integer value (which might be positive or negative). Design an algorithm to count the number of paths that sum to a given value. The path does not need to start or end at the root or a leaf, but it must go downwards (traveling only from parent nodes to child nodes).
Example:
Given the following tree and sum = 22,
5
@@ -31,38 +28,30 @@ Given the following tree and sum = 22,
-
-
Output:
- -3 Explanation: Paths that have sum 22 are: [5,4,11,2], [5,8,4,5], [4,11,7]- -
Note:
- -node number <= 10000
插入。给定两个32位的整数N
与M
,以及表示比特位置的i
与j
。编写一种方法,将M
插入N
,使得M从N的第j位开始,到第i
位结束。假定从j
位到i
位足以容纳M
,也即若M = 10 011,那么j和i之间至少可容纳5个位。例如,不可能出现j = 3和i = 2的情况,因为第3位和第2位之间放不下M。
You are given two 32-bit numbers, N and M, and two bit positions, i and j. Write a method to insert M into N such that M starts at bit j and ends at bit i. You can assume that the bits j through i have enough space to fit all of M. That is, if M = 10011, you can assume that there are at least 5 bits between j and i. You would not, for example, have j = 3 and i = 2, because M could not fully fit between bit 3 and bit 2.
- +You are given two 32-bit numbers, N and M, and two bit positions, i and j. Write a method to insert M into N such that M starts at bit j and ends at bit i. You can assume that the bits j through i have enough space to fit all of M. That is, if M = 10011, you can assume that there are at least 5 bits between j and i. You would not, for example, have j = 3 and i = 2, because M could not fully fit between bit 3 and bit 2.
Example1:
- -Input: N = 10000000000, M = 10011, i = 2, j = 6 @@ -19,12 +16,8 @@- -
Example2:
- -Input: N = 0, M = 11111, i = 0, j = 4 @@ -33,12 +26,8 @@- - - ## Solutions - ### **Python3** @@ -61,8 +50,9 @@ class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/05.02.Bianry Number to String/README.md b/lcci/05.02.Bianry Number to String/README.md index 7a132ad18fd6a..5eb819260427f 100644 --- a/lcci/05.02.Bianry Number to String/README.md +++ b/lcci/05.02.Bianry Number to String/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/05.02.Bianry%20Number%20to%20String/README_EN.md) ## 题目描述 +
二进制数转字符串。给定一个介于0和1之间的实数(如0.72),类型为double,打印它的二进制表达式。如果该数字不在0和1之间,或者无法精确地用32位以内的二进制表示,则打印“ERROR”。
@@ -25,14 +26,14 @@Given a real number between O and 1 (e.g., 0.72) that is passed in as a double, print the binary representation. If the number cannot be represented accurately in binary with at most 32 characters, print "ERROR".
- +Given a real number between O and 1 (e.g., 0.72) that is passed in as a double, print the binary representation. If the number cannot be represented accurately in binary with at most 32 characters, print "ERROR".
Example1:
- -Input: 0.625 @@ -19,12 +16,8 @@- -
Example2:
- -Input: 0.1 @@ -35,22 +28,14 @@- -
Note:
- -给定一个32位整数 num
,你可以将一个数位从0变为1。请编写一个程序,找出你能够获得的最长的一串1的长度。
You have an integer and you can flip exactly one bit from a 0 to a 1. Write code to find the length of the longest sequence of 1s you could create.
- +You have an integer and you can flip exactly one bit from a 0 to a 1. Write code to find the length of the longest sequence of 1s you could create.
Example 1:
- -
Input: num
= 1775(110111011112)
@@ -19,12 +16,8 @@
-
-
Example 2:
- -
Input: num
= 7(01112)
@@ -33,12 +26,8 @@
-
-
-
## Solutions
-
### **Python3**
@@ -54,8 +43,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/lcci/05.04.Closed Number/README.md b/lcci/05.04.Closed Number/README.md
index 7b29c74803a51..f52631bf59c1a 100644
--- a/lcci/05.04.Closed Number/README.md
+++ b/lcci/05.04.Closed Number/README.md
@@ -3,6 +3,7 @@
[English Version](/lcci/05.04.Closed%20Number/README_EN.md)
## 题目描述
+
下一个数。给定一个正整数,找出与其二进制表达式中1的个数相同且大小最接近的那两个数(一个略大,一个略小)。
@@ -27,14 +28,14 @@Given a positive integer, print the next smallest and the next largest number that have the same number of 1 bits in their binary representation.
- +Given a positive integer, print the next smallest and the next largest number that have the same number of 1 bits in their binary representation.
Example1:
- -Input: num = 2 (0b10) @@ -19,12 +16,8 @@- -
Example2:
- -Input: num = 1 @@ -33,23 +26,15 @@- -
Note:
- -1 <= num <= 2147483647
整数转换。编写一个函数,确定需要改变几个位才能将整数A转成整数B。
@@ -26,14 +27,14 @@Write a function to determine the number of bits you would need to flip to convert integer A to integer B.
- +Write a function to determine the number of bits you would need to flip to convert integer A to integer B.
Example1:
- -Input: A = 29 (0b11101), B = 15 (0b01111) @@ -19,12 +16,8 @@- -
Example2:
- -Input: A = 1,B = 2 @@ -33,22 +26,14 @@- -
Note:
- --2147483648 <= A, B <= 2147483647
配对交换。编写程序,交换某个整数的奇数位和偶数位,尽量使用较少的指令(也就是说,位0与位1交换,位2与位3交换,以此类推)。
@@ -26,14 +27,14 @@num
的范围在[0, 2^30 - 1]之间,不会发生整数溢出。Write a program to swap odd and even bits in an integer with as few instructions as possible (e.g., bit 0 and bit 1 are swapped, bit 2 and bit 3 are swapped, and so on).
- +Write a program to swap odd and even bits in an integer with as few instructions as possible (e.g., bit 0 and bit 1 are swapped, bit 2 and bit 3 are swapped, and so on).
Example1:
- -Input: num = 2(0b10) @@ -19,12 +16,8 @@- -
Example2:
- -Input: num = 3 @@ -33,23 +26,15 @@- -
Note:
- -0 <= num <=
2^30 - 1绘制直线。有个单色屏幕存储在一个一维数组中,使得32个连续像素可以存放在一个 int 里。屏幕宽度为w
,且w
可被32整除(即一个 int 不会分布在两行上),屏幕高度可由数组长度及屏幕宽度推算得出。请实现一个函数,绘制从点(x1, y)
到点(x2, y)
的水平线。
A monochrome screen is stored as a single array of int, allowing 32 consecutive pixels to be stored in one int. The screen has width w
, where w
is divisible by 32 (that is, no byte will be split across rows). The height of the screen, of course, can be derived from the length of the array and the width. Implement a function that draws a horizontal line from (x1, y)
to (x2, y)
.
A monochrome screen is stored as a single array of int, allowing 32 consecutive pixels to be stored in one int. The screen has width w
, where w
is divisible by 32 (that is, no byte will be split across rows). The height of the screen, of course, can be derived from the length of the array and the width. Implement a function that draws a horizontal line from (x1, y)
to (x2, y)
.
Given the length of the array, the width of the array (in bit), start position x1
(in bit) of the line, end position x2
(in bit) of the line and the row number y
of the line, return the array after drawing.
Example1:
- -Input: length = 1, w = 32, x1 = 30, x2 = 31, y = 0 @@ -25,12 +20,8 @@- -
Example2:
- -Input: length = 3, w = 96, x1 = 0, x2 = 95, y = 0 @@ -39,10 +30,8 @@- ## Solutions - ### **Python3** @@ -58,8 +47,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/08.01.Three Steps Problem/README.md b/lcci/08.01.Three Steps Problem/README.md index 52f077cc3125c..fa172c0f5a7ee 100644 --- a/lcci/08.01.Three Steps Problem/README.md +++ b/lcci/08.01.Three Steps Problem/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/08.01.Three%20Steps%20Problem/README_EN.md) ## 题目描述 +
三步问题。有个小孩正在上楼梯,楼梯有n阶台阶,小孩一次可以上1阶、2阶或3阶。实现一种方法,计算小孩有多少种上楼梯的方式。结果可能很大,你需要对结果模1000000007。
@@ -27,14 +28,16 @@A child is running up a staircase with n steps and can hop either 1 step, 2 steps, or 3 steps at a time. Implement a method to count how many possible ways the child can run up the stairs. The result may be large, so return it modulo 1000000007.
- +A child is running up a staircase with n steps and can hop either 1 step, 2 steps, or 3 steps at a time. Implement a method to count how many possible ways the child can run up the stairs. The result may be large, so return it modulo 1000000007.
Example1:
- -Input: n = 3 @@ -19,12 +16,8 @@- -
Example2:
- -Input: n = 5 @@ -33,15 +26,12 @@- -
Note:
1. `1 <= n <= 1000000` ## Solutions - ### **Python3** @@ -78,6 +68,7 @@ class Solution { ``` ### **C++** + ```cpp class Solution { public: @@ -97,4 +88,4 @@ public: }; ``` - \ No newline at end of file + diff --git a/lcci/08.02.Robot in a Grid/README.md b/lcci/08.02.Robot in a Grid/README.md index 08e036f2b5ef0..88b4e9c34f6d0 100644 --- a/lcci/08.02.Robot in a Grid/README.md +++ b/lcci/08.02.Robot in a Grid/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/08.02.Robot%20in%20a%20Grid/README_EN.md) ## 题目描述 +设想有个机器人坐在一个网格的左上角,网格 r 行 c 列。机器人只能向下或向右移动,但不能走到一些被禁止的网格(有障碍物)。设计一种算法,寻找机器人从左上角移动到右下角的路径。
@@ -27,14 +28,14 @@说明:r 和 c 的值均不超过 100。
- ## 解法 - + ### **Python3** + ```python @@ -42,6 +43,7 @@ ``` ### **Java** + ```java @@ -49,8 +51,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/08.02.Robot in a Grid/README_EN.md b/lcci/08.02.Robot in a Grid/README_EN.md index f404b3f5aa0a5..6c2de546ee6e8 100644 --- a/lcci/08.02.Robot in a Grid/README_EN.md +++ b/lcci/08.02.Robot in a Grid/README_EN.md @@ -3,21 +3,17 @@ [中文文档](/lcci/08.02.Robot%20in%20a%20Grid/README.md) ## Description -Imagine a robot sitting on the upper left corner of grid with r rows and c columns. The robot can only move in two directions, right and down, but certain cells are "off limits" such that the robot cannot step on them. Design an algorithm to find a path for the robot from the top left to the bottom right.
+Imagine a robot sitting on the upper left corner of grid with r rows and c columns. The robot can only move in two directions, right and down, but certain cells are "off limits" such that the robot cannot step on them. Design an algorithm to find a path for the robot from the top left to the bottom right.
"off limits" and empty grid are represented by 1
and 0
respectively.
Return a valid path, consisting of row number and column number of grids in the path.
-Example 1:
- -Input: @@ -34,19 +30,14 @@ Output: [[0,0],[0,1],[0,2],[1,2],[2,2]]- -
Note:
- -r, c <= 100
魔术索引。 在数组A[0...n-1]
中,有所谓的魔术索引,满足条件A[i] = i
。给定一个有序整数数组,编写一种方法找出魔术索引,若有的话,在数组A中找出一个魔术索引,如果没有,则返回-1。若有多个魔术索引,返回索引值最小的一个。
A magic index in an array A[0...n-1]
is defined to be an index such that A[i] = i
. Given a sorted array of distinct integers, write a method to find a magic index, if one exists, in array A. If not, return -1. If there are more than one magic index, return the smallest one.
A magic index in an array A[0...n-1]
is defined to be an index such that A[i] = i
. Given a sorted array of distinct integers, write a method to find a magic index, if one exists, in array A. If not, return -1. If there are more than one magic index, return the smallest one.
Example1:
- -Input: nums = [0, 2, 3, 4, 5] @@ -19,12 +16,8 @@- -
Example2:
- -Input: nums = [1, 1, 1] @@ -33,20 +26,14 @@- -
Note:
1 <= nums.length <= 1000000
幂集。编写一种方法,返回某集合的所有子集。集合中不包含重复的元素。
@@ -24,14 +25,14 @@ ] - ## 解法 - + ### **Python3** + ```python @@ -39,6 +40,7 @@ ``` ### **Java** + ```java @@ -46,8 +48,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/08.04.Power Set/README_EN.md b/lcci/08.04.Power Set/README_EN.md index 30dfe81f8e3ed..598f8e52626dc 100644 --- a/lcci/08.04.Power Set/README_EN.md +++ b/lcci/08.04.Power Set/README_EN.md @@ -3,18 +3,13 @@ [中文文档](/lcci/08.04.Power%20Set/README.md) ## Description -Write a method to return all subsets of a set. The elements in a set are pairwise distinct.
- +Write a method to return all subsets of a set. The elements in a set are pairwise distinct.
Note: The result set should not contain duplicated subsets.
- -Example:
- -Input: nums = [1,2,3] @@ -43,12 +38,8 @@- - - ## Solutions - ### **Python3** @@ -64,8 +55,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/08.05.Recursive Mulitply/README.md b/lcci/08.05.Recursive Mulitply/README.md index 2d99c79302cfd..db0e67ec277d9 100644 --- a/lcci/08.05.Recursive Mulitply/README.md +++ b/lcci/08.05.Recursive Mulitply/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/08.05.Recursive%20Mulitply/README_EN.md) ## 题目描述 +
递归乘法。 写一个递归函数,不使用 * 运算符, 实现两个正整数的相乘。可以使用加号、减号、位移,但要吝啬一些。
@@ -26,14 +27,14 @@Write a recursive function to multiply two positive integers without using the * operator. You can use addition, subtraction, and bit shifting, but you should minimize the number of those operations.
- +Write a recursive function to multiply two positive integers without using the * operator. You can use addition, subtraction, and bit shifting, but you should minimize the number of those operations.
Example 1:
- -Input: A = 1, B = 10 @@ -19,12 +16,8 @@- -
Example 2:
- -Input: A = 3, B = 4 @@ -33,22 +26,14 @@- -
Note:
- -在经典汉诺塔问题中,有 3 根柱子及 N 个不同大小的穿孔圆盘,盘子可以滑入任意一根柱子。一开始,所有盘子自上而下按升序依次套在第一根柱子上(即每一个盘子只能放在更大的盘子上面)。移动圆盘时受到以下限制:
(1) 每次只能移动一个盘子;
@@ -31,14 +32,14 @@
In the classic problem of the Towers of Hanoi, you have 3 towers and N disks of different sizes which can slide onto any tower. The puzzle starts with disks sorted in ascending order of size from top to bottom (i.e., each disk sits on top of an even larger one). You have the following constraints:
- +In the classic problem of the Towers of Hanoi, you have 3 towers and N disks of different sizes which can slide onto any tower. The puzzle starts with disks sorted in ascending order of size from top to bottom (i.e., each disk sits on top of an even larger one). You have the following constraints:
(1) Only one disk can be moved at a time.
@@ -13,16 +12,10 @@
(3) A disk cannot be placed on top of a smaller disk.
Write a program to move the disks from the first tower to the last using stacks.
- -Example1:
- -Input: A = [2, 1, 0], B = [], C = [] @@ -31,12 +24,8 @@- -
Example2:
- -Input: A = [1, 0], B = [], C = [] @@ -45,22 +34,14 @@- -
Note:
- -A.length <= 14
无重复字符串的排列组合。编写一种方法,计算某字符串的所有排列组合,字符串每个字符均不相同。
@@ -27,14 +28,14 @@Write a method to compute all permutations of a string of unique characters.
- +Write a method to compute all permutations of a string of unique characters.
Example1:
- -Input: S = "qwe" @@ -19,12 +16,8 @@- -
Example2:
- -Input: S = "ab" @@ -33,23 +26,15 @@- -
Note:
- -1 <= S.length <= 9
有重复字符串的排列组合。编写一种方法,计算某字符串的所有排列组合。
@@ -25,14 +26,14 @@Write a method to compute all permutations of a string whose charac ters are not necessarily unique. The list of permutations should not have duplicates.
- +Write a method to compute all permutations of a string whose charac ters are not necessarily unique. The list of permutations should not have duplicates.
Example1:
- -Input: S = "qqe" @@ -19,12 +16,8 @@- -
Example2:
- -Input: S = "ab" @@ -33,23 +26,15 @@- -
Note:
- -1 <= S.length <= 9
括号。设计一种算法,打印n对括号的所有合法的(例如,开闭一一对应)组合。
@@ -20,15 +21,16 @@ ] - ## 解法 - + ### **Python3** + + 递归求解。其中,`left` 表示剩余的 `(`,`right` 表示剩余的 `)`。 - 当 `left` > `right` 时,说明 state 中 `(` 少于 `)`,不是合法组合,直接剪枝; @@ -36,7 +38,6 @@ - 当 `left` > 0 时,此时可往 state 添加一个 `(`; - 当 `right` > 0 时,此时可往 state 添加一个 `)`。 - ```python class Solution: def generateParenthesis(self, n: int) -> List[str]: @@ -57,6 +58,7 @@ class Solution: ``` ### **Java** + ```java @@ -88,8 +90,9 @@ class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/08.09.Bracket/README_EN.md b/lcci/08.09.Bracket/README_EN.md index c135bd340eabb..5caf97cc420c7 100644 --- a/lcci/08.09.Bracket/README_EN.md +++ b/lcci/08.09.Bracket/README_EN.md @@ -3,18 +3,13 @@ [中文文档](/lcci/08.09.Bracket/README.md) ## Description -Implement an algorithm to print all valid (e.g., properly opened and closed) combinations of n pairs of parentheses.
- +Implement an algorithm to print all valid (e.g., properly opened and closed) combinations of n pairs of parentheses.
Note: The result set should not contain duplicated subsets.
- -For example, given n = 3, the result should be:
- -[ @@ -33,12 +28,8 @@- - - ## Solutions - ### **Python3** @@ -92,8 +83,9 @@ class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/08.10.Color Fill/README.md b/lcci/08.10.Color Fill/README.md index 5bad11db6057b..6973a51f58a59 100644 --- a/lcci/08.10.Color Fill/README.md +++ b/lcci/08.10.Color Fill/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/08.10.Color%20Fill/README_EN.md) ## 题目描述 +
颜色填充。编写函数,实现许多图片编辑软件都支持的“颜色填充”功能。给定一个屏幕(以二维数组表示,元素为颜色值)、一个点和一个新的颜色值,将新颜色值填入这个点的周围区域,直到原来的颜色值全都改变。
@@ -28,14 +29,14 @@ sr = 1, sc = 1, newColor = 2Implement the "paint fill" function that one might see on many image editing programs. That is, given a screen (represented by a two-dimensional array of colors), a point, and a new color, fill in the surrounding area until the color changes from the original color.
- +Implement the "paint fill" function that one might see on many image editing programs. That is, given a screen (represented by a two-dimensional array of colors), a point, and a new color, fill in the surrounding area until the color changes from the original color.
Example1:
- -Input: @@ -31,24 +28,16 @@ Note the bottom corner is not colored 2, because it is not 4-directionally conne to the starting pixel.- -
Note:
- -image
and image[0]
will be in the range [1, 50]
.0 <= sr < image.length
and 0 <= sc < image[0].length
.image[i][j]
and newColor
will be an integer in [0, 65535]
.硬币。给定数量不限的硬币,币值为25分、10分、5分和1分,编写代码计算n分有几种表示法。(结果可能会很大,你需要将结果模上1000000007)
@@ -38,14 +39,14 @@Given an infinite number of quarters (25 cents), dimes (10 cents), nickels (5 cents), and pennies (1 cent), write code to calculate the number of ways of representing n cents. (The result may be large, so you should return it modulo 1000000007)
- +Given an infinite number of quarters (25 cents), dimes (10 cents), nickels (5 cents), and pennies (1 cent), write code to calculate the number of ways of representing n cents. (The result may be large, so you should return it modulo 1000000007)
Example1:
-Input: n = 5 @@ -24,12 +22,8 @@- -
Example2:
- -Input: n = 10 @@ -48,26 +42,16 @@- -
Notes:
- -You can assume:
- -设计一种算法,打印 N 皇后在 N × N 棋盘上的各种摆法,其中每个皇后都不同行、不同列,也不在对角线上。这里的“对角线”指的是所有的对角线,不只是平分整个棋盘的那两条对角线。
@@ -26,14 +27,14 @@ ] - ## 解法 - + ### **Python3** + ```python @@ -41,6 +42,7 @@ ``` ### **Java** + ```java @@ -48,8 +50,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/08.12.Eight Queens/README_EN.md b/lcci/08.12.Eight Queens/README_EN.md index c8e9f021fe427..b3d13b07cb99a 100644 --- a/lcci/08.12.Eight Queens/README_EN.md +++ b/lcci/08.12.Eight Queens/README_EN.md @@ -3,18 +3,13 @@ [中文文档](/lcci/08.12.Eight%20Queens/README.md) ## Description -Write an algorithm to print all ways of arranging n queens on an n x n chess board so that none of them share the same row, column, or diagonal. In this case, "diagonal" means all diagonals, not just the two that bisect the board.
- +Write an algorithm to print all ways of arranging n queens on an n x n chess board so that none of them share the same row, column, or diagonal. In this case, "diagonal" means all diagonals, not just the two that bisect the board.
Notes: This problem is a generalization of the original one in the book.
- -Example:
- -Input: 4 @@ -47,12 +42,8 @@- - - ## Solutions - ### **Python3** @@ -68,8 +59,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/08.13.Pile Box/README.md b/lcci/08.13.Pile Box/README.md index 413d38ba51eed..ee3c3b0ff6c2b 100644 --- a/lcci/08.13.Pile Box/README.md +++ b/lcci/08.13.Pile Box/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/08.13.Pile%20Box/README_EN.md) ## 题目描述 +
堆箱子。给你一堆n个箱子,箱子宽 wi、高hi、深di。箱子不能翻转,将箱子堆起来时,下面箱子的宽度、高度和深度必须大于上面的箱子。实现一种方法,搭出最高的一堆箱子。箱堆的高度为每个箱子高度的总和。
@@ -26,14 +27,14 @@You have a stack of n boxes, with widths wi, heights hi, and depths di. The boxes cannot be rotated and can only be stacked on top of one another if each box in the stack is strictly larger than the box above it in width, height, and depth. Implement a method to compute the height of the tallest possible stack. The height of a stack is the sum of the heights of each box.
The input use [wi, di, hi]
to represents each box.
Example2:
- -Input: box = [[1, 1, 1], [2, 3, 4], [2, 6, 7], [3, 4, 5]] @@ -35,12 +34,8 @@
box.length <= 3000
给定一个布尔表达式和一个期望的布尔结果 result,布尔表达式由 0
(false)、1
(true)、&
(AND)、 |
(OR) 和 ^
(XOR) 符号组成。实现一个函数,算出有几种可使该表达式得出 result 值的括号方法。
Given a boolean expression consisting of the symbols 0
(false), 1
(true), &
(AND), |
(OR), and ^
(XOR), and a desired boolean result value result, implement a function to count the number of ways of parenthesizing the expression such that it evaluates to result.
Given a boolean expression consisting of the symbols 0
(false), 1
(true), &
(AND), |
(OR), and ^
(XOR), and a desired boolean result value result, implement a function to count the number of ways of parenthesizing the expression such that it evaluates to result.
Example 1:
- -Input: s = "1^0|0|1", result = 0 @@ -27,12 +24,8 @@- -
Example 2:
- -Input: s = "0&0&0&1^1|0", result = 1 @@ -41,20 +34,14 @@ Output: 10- -
Note:
s
.给定两个排序后的数组 A 和 B,其中 A 的末端有足够的缓冲空间容纳 B。 编写一个方法,将 B 合并入 A 并排序。
@@ -22,14 +23,14 @@ B = [2,5,6], n = 3A.length == n + m
You are given two sorted arrays, A and B, where A has a large enough buffer at the end to hold B. Write a method to merge B into A in sorted order.
- +You are given two sorted arrays, A and B, where A has a large enough buffer at the end to hold B. Write a method to merge B into A in sorted order.
Initially the number of elements in A and B are m and n respectively.
- -Example:
- -Input: @@ -27,12 +22,8 @@ B = [2,5,6], n = 3 Output: [1,2,2,3,5,6]- - - ## Solutions - ### **Python3** @@ -48,8 +39,9 @@ B = [2,5,6], n = 3 ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/10.02.Group Anagrams/README.md b/lcci/10.02.Group Anagrams/README.md index f9b57de870bc2..23c2edaa735a2 100644 --- a/lcci/10.02.Group Anagrams/README.md +++ b/lcci/10.02.Group Anagrams/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/10.02.Group%20Anagrams/README_EN.md) ## 题目描述 +
编写一种方法,对字符串数组进行排序,将所有变位词组合在一起。变位词是指字母相同,但排列不同的字符串。
@@ -25,14 +26,14 @@Write a method to sort an array of strings so that all the anagrams are in the same group.
- +Write a method to sort an array of strings so that all the anagrams are in the same group.
Note: This problem is slightly different from the original one the book.
- -Example:
- -
Input: ["eat", "tea", "tan", "ate", "nat", "bat"]
,
@@ -31,23 +26,15 @@
]
-
-
Notes:
- -搜索旋转数组。给定一个排序后的数组,包含n个整数,但这个数组已被旋转过很多次了,次数不详。请编写代码找出数组中的某个元素,假设数组元素原先是按升序排列的。若有多个相同元素,返回索引值最小的一个。
@@ -24,14 +25,14 @@Given a sorted array of n integers that has been rotated an unknown number of times, write code to find an element in the array. You may assume that the array was originally sorted in increasing order. If there are more than one target elements in the array, return the smallest index.
- +Given a sorted array of n integers that has been rotated an unknown number of times, write code to find an element in the array. You may assume that the array was originally sorted in increasing order. If there are more than one target elements in the array, return the smallest index.
Example1:
- -Input: arr = [15, 16, 19, 20, 25, 1, 3, 4, 5, 7, 10, 14], target = 5 @@ -19,12 +16,8 @@- -
Example2:
- -Input: arr = [15, 16, 19, 20, 25, 1, 3, 4, 5, 7, 10, 14], target = 11 @@ -33,20 +26,14 @@- -
Note:
1 <= arr.length <= 1000000
稀疏数组搜索。有个排好序的字符串数组,其中散布着一些空字符串,编写一种方法,找出给定字符串的位置。
@@ -25,14 +26,14 @@Given a sorted array of strings that is interspersed with empty strings, write a method to find the location of a given string.
- +Given a sorted array of strings that is interspersed with empty strings, write a method to find the location of a given string.
Example1:
- -Input: words = ["at", "", "", "", "ball", "", "", "car", "", "","dad", "", ""], s = "ta" @@ -19,12 +16,8 @@- -
Example2:
- -Input: words = ["at", "", "", "", "ball", "", "", "car", "", "","dad", "", ""], s = "ball" @@ -33,21 +26,14 @@- -
Note:
-1 <= words.length <= 1000000
给定M×N矩阵,每一行、每一列都按升序排列,请编写代码找出某元素。
@@ -23,14 +24,16 @@给定 target = 20
,返回 false
。
Given an M x N matrix in which each row and each column is sorted in ascending order, write a method to find an element.
- +Given an M x N matrix in which each row and each column is sorted in ascending order, write a method to find an element.
Example:
- -Given matrix:
- -[ @@ -33,20 +28,12 @@- -
Given target = 5, return true.
Given target = 20, return false.
假设你正在读取一串整数。每隔一段时间,你希望能找出数字 x 的秩(小于或等于 x 的值的个数)。请实现数据结构和算法来支持这些操作,也就是说:
@@ -28,14 +29,14 @@track
和 getRankOfNumber
方法的调用次数均不超过 2000 次Imagine you are reading in a stream of integers. Periodically, you wish to be able to look up the rank of a number x
(the number of values less than or equal to x
). lmplement the data structures and algorithms to support these operations. That is, implement the method track (int x)
, which is called when each number is generated, and the method getRankOfNumber(int x)
, which returns the number of values less than or equal to x
.
Imagine you are reading in a stream of integers. Periodically, you wish to be able to look up the rank of a number x
(the number of values less than or equal to x
). lmplement the data structures and algorithms to support these operations. That is, implement the method track (int x)
, which is called when each number is generated, and the method getRankOfNumber(int x)
, which returns the number of values less than or equal to x
.
Note: This problem is slightly different from the original one in the book.
- -Example:
- -Input: @@ -29,21 +24,15 @@- -
Note:
- -x <= 50000
track
and getRankOfNumber
methods are less than or equal to 2000.在一个整数数组中,“峰”是大于或等于相邻整数的元素,相应地,“谷”是小于或等于相邻整数的元素。例如,在数组{5, 8, 6, 2, 3, 4, 6}中,{8, 6}是峰, {5, 2}是谷。现在给定一个整数数组,将该数组按峰与谷的交替顺序排序。
@@ -18,14 +19,14 @@nums.length <= 10000
In an array of integers, a "peak" is an element which is greater than or equal to the adjacent integers and a "valley" is an element which is less than or equal to the adjacent integers. For example, in the array {5, 8, 6, 2, 3, 4, 6}, {8, 6} are peaks and {5, 2} are valleys. Given an array of integers, sort the array into an alternating sequence of peaks and valleys.
- +In an array of integers, a "peak" is an element which is greater than or equal to the adjacent integers and a "valley" is an element which is less than or equal to the adjacent integers. For example, in the array {5, 8, 6, 2, 3, 4, 6}, {8, 6} are peaks and {5, 2} are valleys. Given an array of integers, sort the array into an alternating sequence of peaks and valleys.
Example:
- -Input: [5, 3, 1, 2, 3] @@ -19,20 +16,14 @@- -
Note:
nums.length <= 10000
编写一个函数,不用临时变量,直接交换numbers = [a, b]
中a
与b
的值。
示例:
@@ -14,14 +15,16 @@numbers.length == 2
Write a function to swap a number in place (that is, without temporary vari ables).
- +Write a function to swap a number in place (that is, without temporary vari ables).
Example:
- -Input: numbers = [1,2] @@ -19,22 +16,14 @@- -
Note:
- -numbers.length == 2
设计一个方法,找出任意指定单词在一本书中的出现频率。
你的实现应该支持如下操作:
@@ -26,14 +27,14 @@ wordsFrequency.get("pen"); //返回1get
函数的调用次数不会超过100000Design a method to find the frequency of occurrences of any given word in a book. What if we were running this algorithm multiple times?
- +Design a method to find the frequency of occurrences of any given word in a book. What if we were running this algorithm multiple times?
You should implement following methods:
- -WordsFrequency(book)
constructor, parameter is a array of strings, representing the book.get(word)
get the frequency of word
in the book. Example:
- -WordsFrequency wordsFrequency = new WordsFrequency({"i", "have", "an", "apple", "he", "have", "a", "pen"}); @@ -38,30 +31,22 @@ wordsFrequency.get("pen"); //returns 1- -
Note:
- -There are only lowercase letters in book[i].
There are only lowercase letters in book[i].
1 <= book.length <= 100000
1 <= book.length <= 100000
1 <= book[i].length <= 10
1 <= book[i].length <= 10
get
function will not be called more than 100000 times.get
function will not be called more than 100000 times.给定两条线段(表示为起点start = {X1, Y1}
和终点end = {X2, Y2}
),如果它们有交点,请计算其交点,没有交点则返回空值。
10^-6
。若有多个交点(线段重叠)则返回X值最小的点,X坐标相同则返回Y值最小的点。
@@ -30,14 +31,14 @@ line2 = {1, 0}, {2, 1}
Given two straight line segments (represented as a start point and an end point), compute the point of intersection, if any. If there's no intersection, return an empty array.
The absolute error should not exceed 10^-6. If there are more than one intersections, return the one with smallest X axis value. If there are more than one intersections that have same X axis value, return the one with smallest Y axis value. - -Example 1:
- -Input: @@ -25,12 +22,8 @@ line2 = {1, 1}, {0, -1}- -
Example 2:
- -Input: @@ -43,12 +36,8 @@ line2 = {1, 1}, {2, 2}- -
Example 3:
- -Input: @@ -61,23 +50,15 @@ line2 = {1, 0}, {2, 1}- -
Note:
- -设计一个算法,判断玩家是否赢了井字游戏。输入是一个 N x N 的数组棋盘,由字符" ","X"和"O"组成,其中字符" "代表一个空位。
@@ -46,14 +47,14 @@Design an algorithm to figure out if someone has won a game of tic-tac-toe. Input is a string array of size N x N, including characters " ", "X" and "O", where " " represents a empty grid.
- +Design an algorithm to figure out if someone has won a game of tic-tac-toe. Input is a string array of size N x N, including characters " ", "X" and "O", where " " represents a empty grid.
The rules of tic-tac-toe are as follows:
- -If there is any winner, return the character that the winner used. If there's a draw, return "Draw". If the game doesn't end and there is no winner, return "Pending".
- -Example 1:
- -Input: board = ["O X"," XO","X O"] @@ -38,12 +29,8 @@- -
Example 2:
- -Input: board = ["OOX","XXO","OXO"] @@ -54,12 +41,8 @@- -
Example 3:
- -Input: board = ["OOX","XXO","OX "] @@ -70,23 +53,15 @@- -
Note:
- -1 <= board.length == board[i].length <= 100
设计一个算法,算出 n 阶乘有多少个尾随零。
@@ -20,14 +21,14 @@说明: 你算法的时间复杂度应为 O(log n) 。
- ## 解法 - + ### **Python3** + ```python @@ -35,6 +36,7 @@ ``` ### **Java** + ```java @@ -42,8 +44,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/16.05.Factorial Zeros/README_EN.md b/lcci/16.05.Factorial Zeros/README_EN.md index 8bae56b4ac752..5321bee114b68 100644 --- a/lcci/16.05.Factorial Zeros/README_EN.md +++ b/lcci/16.05.Factorial Zeros/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/lcci/16.05.Factorial%20Zeros/README.md) ## Description -Write an algorithm which computes the number of trailing zeros in n factorial.
- +Write an algorithm which computes the number of trailing zeros in n factorial.
Example 1:
- -Input: 3 @@ -19,12 +16,8 @@ Explanation: 3! = 6, no trailing zero.- -
Example 2:
- -Input: 5 @@ -33,16 +26,10 @@ Explanation: 5! = 120, one trailing zero.- -
Note: Your solution should be in logarithmic time complexity.
- - - ## Solutions - ### **Python3** @@ -58,8 +45,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/16.06.Smallest Difference/README.md b/lcci/16.06.Smallest Difference/README.md index dcdd323961aef..095a40953c318 100644 --- a/lcci/16.06.Smallest Difference/README.md +++ b/lcci/16.06.Smallest Difference/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/16.06.Smallest%20Difference/README_EN.md) ## 题目描述 +给定两个整数数组a
和b
,计算具有最小差绝对值的一对数值(每个数组中取一个值),并返回该对数值的差
示例:
@@ -16,14 +17,14 @@Given two arrays of integers, compute the pair of values (one value in each array) with the smallest (non-negative) difference. Return the difference.
- +Given two arrays of integers, compute the pair of values (one value in each array) with the smallest (non-negative) difference. Return the difference.
Example:
- -Input: {1, 3, 15, 11, 2}, {23, 127, 235, 19, 8} @@ -19,24 +16,16 @@- -
Note:
- -1 <= a.length, b.length <= 100000
-2147483648 <= a[i], b[i] <= 2147483647
编写一个方法,找出两个数字a
和b
中最大的那一个。不得使用if-else或其他比较运算符。
示例:
@@ -10,14 +11,14 @@ 输出: 2 - ## 解法 - + ### **Python3** + ```python @@ -25,6 +26,7 @@ ``` ### **Java** + ```java @@ -32,8 +34,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/16.07.Maximum/README_EN.md b/lcci/16.07.Maximum/README_EN.md index 12d35005e26a9..383dccaa3619e 100644 --- a/lcci/16.07.Maximum/README_EN.md +++ b/lcci/16.07.Maximum/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/lcci/16.07.Maximum/README.md) ## Description -Write a method that finds the maximum of two numbers. You should not use if-else or any other comparison operator.
- +Write a method that finds the maximum of two numbers. You should not use if-else or any other comparison operator.
Example:
- -Input: a = 1, b = 2 @@ -19,12 +16,8 @@- - - ## Solutions - ### **Python3** @@ -40,8 +33,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/16.08.English Int/README.md b/lcci/16.08.English Int/README.md index 3ee7b199a0ce0..190d0c85176ac 100644 --- a/lcci/16.08.English Int/README.md +++ b/lcci/16.08.English Int/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/16.08.English%20Int/README_EN.md) ## 题目描述 +
给定一个整数,打印该整数的英文描述。
@@ -27,14 +28,14 @@输入: 1234567891 输出: "One Billion Two Hundred Thirty Four Million Five Hundred Sixty Seven Thousand Eight Hundred Ninety One"- ## 解法 - + ### **Python3** + ```python @@ -42,6 +43,7 @@ ``` ### **Java** + ```java @@ -49,8 +51,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/16.08.English Int/README_EN.md b/lcci/16.08.English Int/README_EN.md index 9b31609ed807b..36cbf4a929af1 100644 --- a/lcci/16.08.English Int/README_EN.md +++ b/lcci/16.08.English Int/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/lcci/16.08.English%20Int/README.md) ## Description -
Given any integer, print an English phrase that describes the integer (e.g., "One Thousand Two Hundred Thirty Four").
- +Given any integer, print an English phrase that describes the integer (e.g., "One Thousand Two Hundred Thirty Four").
Example 1:
- -Input: 123 @@ -19,48 +16,32 @@- -
Example 2:
- -Input: 12345 Output: "Twelve Thousand Three Hundred Forty Five"- -
Example 3:
- -Input: 1234567 Output: "One Million Two Hundred Thirty Four Thousand Five Hundred Sixty Seven"- -
Example 4:
- -Input: 1234567891 Output: "One Billion Two Hundred Thirty Four Million Five Hundred Sixty Seven Thousand Eight Hundred Ninety One"- - - ## Solutions - ### **Python3** @@ -76,8 +57,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/16.09.Operations/README.md b/lcci/16.09.Operations/README.md index 8152f83e63451..26e90abdf3666 100644 --- a/lcci/16.09.Operations/README.md +++ b/lcci/16.09.Operations/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/16.09.Operations/README_EN.md) ## 题目描述 +
请实现整数数字的乘法、减法和除法运算,运算结果均为整数数字,程序中只允许使用加法运算符和逻辑运算符,允许程序中出现正负常数,不允许使用位运算。
你的实现应该支持如下操作:
@@ -24,14 +25,14 @@ operations.divide(5, -2); //返回-2rite methods to implement the multiply, subtract, and divide operations for integers. The results of all of these are integers. Use only the add operator.
- +rite methods to implement the multiply, subtract, and divide operations for integers. The results of all of these are integers. Use only the add operator.
You should implement following methods:
- -Operations()
constructorminus(a, b)
Subtraction, returns a - b
divide(a, b)
Division, returns a / b
Example:
- -Operations operations = new Operations(); @@ -36,26 +29,18 @@ operations.divide(5, -2); //returns -2- -
Note:
- -给定N个人的出生年份和死亡年份,第i
个人的出生年份为birth[i]
,死亡年份为death[i]
,实现一个方法以计算生存人数最多的年份。
你可以假设所有人都出生于1900年至2000年(含1900和2000)之间。如果一个人在某一年的任意时期都处于生存状态,那么他们应该被纳入那一年的统计中。例如,生于1908年、死于1909年的人应当被列入1908年和1909年的计数。
@@ -19,14 +20,14 @@ death = {1948, 1951, 2000}birth[i] <= death[i]
Given a list of people with their birth and death years, implement a method to compute the year with the most number of people alive. You may assume that all people were born between 1900 and 2000 (inclusive). If a person was alive during any portion of that year, they should be included in that year's count. For example, Person (birth= 1908, death= 1909) is included in the counts for both 1908 and 1909.
- +Given a list of people with their birth and death years, implement a method to compute the year with the most number of people alive. You may assume that all people were born between 1900 and 2000 (inclusive). If a person was alive during any portion of that year, they should be included in that year's count. For example, Person (birth= 1908, death= 1909) is included in the counts for both 1908 and 1909.
If there are more than one years that have the most number of people alive, return the smallest one.
- -Example:
- -Input: @@ -27,23 +22,15 @@ death = {1948, 1951, 2000}- -
Note:
- -0 < birth.length == death.length <= 10000
birth[i] <= death[i]
你正在使用一堆木板建造跳水板。有两种类型的木板,其中长度较短的木板长度为shorter
,长度较长的木板长度为longer
。你必须正好使用k
块木板。编写一个方法,生成跳水板所有可能的长度。
返回的长度需要从小到大排列。
@@ -19,14 +20,14 @@ k = 3You are building a diving board by placing a bunch of planks of wood end-to-end. There are two types of planks, one of length shorter
and one of length longer
. You must use exactly K
planks of wood. Write a method to generate all possible lengths for the diving board.
You are building a diving board by placing a bunch of planks of wood end-to-end. There are two types of planks, one of length shorter
and one of length longer
. You must use exactly K
planks of wood. Write a method to generate all possible lengths for the diving board.
return all lengths in non-decreasing order.
- -Example:
- -Input: @@ -29,23 +24,15 @@ k = 3- -
Note:
- -给定两个正方形及一个二维平面。请找出将这两个正方形分割成两半的一条直线。假设正方形顶边和底边与 x 轴平行。
@@ -26,14 +27,14 @@ square2 = {0, -1, 2}square[2] > 0
Given two squares on a two-dimensional plane, find a line that would cut these two squares in half. Assume that the top and the bottom sides of the square run parallel to the x-axis.
- +Given two squares on a two-dimensional plane, find a line that would cut these two squares in half. Assume that the top and the bottom sides of the square run parallel to the x-axis.
Each square consists of three values, the coordinate of bottom left corner [X,Y] = [square[0],square[1]]
, and the side length of the square square[2]
. The line will intersect to the two squares in four points. Return the coordinates of two intersection points [X1,Y1]
and [X2,Y2]
that the forming segment covers the other two intersection points in format of {X1,Y1,X2,Y2}
. If X1 != X2
, there should be X1 < X2
, otherwise there should be Y1 <= Y2
.
If there are more than one line that can cut these two squares in half, return the one that has biggest slope (slope of a line parallel to the y-axis is considered as infinity).
- -Example:
- -Input: @@ -33,23 +26,15 @@ square2 = {0, -1, 2}- -
Note:
- -square.length == 3
square[2] > 0
给定一个二维平面及平面上的 N 个点列表Points
,其中第i
个点的坐标为Points[i]=[Xi,Yi]
。请找出一条直线,其通过的点的数目最多。
设穿过最多点的直线所穿过的全部点编号从小到大排序的列表为S
,你仅需返回[S[0],S[1]]
作为答案,若有多条直线穿过了相同数量的点,则选择S[0]
值较小的直线返回,S[0]
相同则选择S[1]
值较小的直线返回。
len(Points[i]) = 2
Given a two-dimensional graph with points on it, find a line which passes the most number of points.
- +Given a two-dimensional graph with points on it, find a line which passes the most number of points.
Assume all the points that passed by the line are stored in list S
sorted by their number. You need to return [S[0], S[1]]
, that is , two points that have smallest number. If there are more than one line that passes the most number of points, choose the one that has the smallest S[0].
If there are more that one line that has the same S[0]
, choose the one that has smallest S[1]
.
Example:
- -Input: [[0,0],[1,1],[1,0],[2,0]] @@ -25,23 +20,15 @@- -
Note:
- -2 <= len(Points) <= 300
len(Points[i]) = 2
珠玑妙算游戏(the game of master mind)的玩法如下。
计算机有4个槽,每个槽放一个球,颜色可能是红色(R)、黄色(Y)、绿色(G)或蓝色(B)。例如,计算机可能有RGGB 4种(槽1为红色,槽2、3为绿色,槽4为蓝色)。作为用户,你试图猜出颜色组合。打个比方,你可能会猜YRGB。要是猜对某个槽的颜色,则算一次“猜中”;要是只猜对颜色但槽位猜错了,则算一次“伪猜中”。注意,“猜中”不能算入“伪猜中”。
@@ -18,14 +19,14 @@solution
和guess
仅包含"R"
,"G"
,"B"
,"Y"
这4种字符The Game of Master Mind is played as follows:
- +The Game of Master Mind is played as follows:
The computer has four slots, and each slot will contain a ball that is red (R). yellow (Y). green (G) or blue (B). For example, the computer might have RGGB (Slot #1 is red, Slots #2 and #3 are green, Slot #4 is blue).
- -You, the user, are trying to guess the solution. You might, for example, guess YRGB.
- -When you guess the correct color for the correct slot, you get a "hit:' If you guess a color that exists but is in the wrong slot, you get a "pseudo-hit:' Note that a slot that is a hit can never count as a pseudo-hit.
- -For example, if the actual solution is RGBY and you guess GGRR, you have one hit and one pseudo-hit. Write a method that, given a guess and a solution, returns the number of hits and pseudo-hits.
- -Given a sequence of colors solution
, and a guess
, write a method that return the number of hits and pseudo-hit answer
, where answer[0]
is the number of hits and answer[1]
is the number of pseudo-hit.
Example:
- -Input: solution="RGBY",guess="GGRR" @@ -41,23 +28,15 @@- -
Note:
- -len(solution) = len(guess) = 4
"R"
,"G"
,"B"
,"Y"
in solution
and guess
.给定一个整数数组,编写一个函数,找出索引m
和n
,只要将索引区间[m,n]
的元素排好序,整个数组就是有序的。注意:n-m
尽量最小,也就是说,找出符合条件的最短序列。函数返回值为[m,n]
,若不存在这样的m
和n
(例如整个数组是有序的),请返回[-1,-1]
。
示例:
@@ -14,14 +15,14 @@0 <= len(array) <= 1000000
Given an array of integers, write a method to find indices m and n such that if you sorted elements m through n, the entire array would be sorted. Minimize n - m
(that is, find the smallest such sequence).
Given an array of integers, write a method to find indices m and n such that if you sorted elements m through n, the entire array would be sorted. Minimize n - m
(that is, find the smallest such sequence).
Return [m,n]
. If there are no such m and n (e.g. the array is already sorted), return [-1, -1].
Example:
- -Input: [1,2,4,7,10,11,7,12,6,7,16,18,19] @@ -23,22 +18,14 @@- -
Note:
- -0 <= len(array) <= 1000000
给定一个整数数组(有正数有负数),找出总和最大的连续数列,并返回总和。
@@ -17,14 +18,14 @@如果你已经实现复杂度为 O(n) 的解法,尝试使用更为精妙的分治法求解。
- ## 解法 - + ### **Python3** + ```python @@ -32,6 +33,7 @@ ``` ### **Java** + ```java @@ -39,8 +41,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/16.17.Contiguous Sequence/README_EN.md b/lcci/16.17.Contiguous Sequence/README_EN.md index d9a17e1758f43..403565fbeceb0 100644 --- a/lcci/16.17.Contiguous Sequence/README_EN.md +++ b/lcci/16.17.Contiguous Sequence/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/lcci/16.17.Contiguous%20Sequence/README.md) ## Description -You are given an array of integers (both positive and negative). Find the contiguous sequence with the largest sum. Return the sum.
- +You are given an array of integers (both positive and negative). Find the contiguous sequence with the largest sum. Return the sum.
Example:
- -Input: [-2,1,-3,4,-1,2,1,-5,4] @@ -21,20 +18,12 @@- -
Follow Up:
- -If you have figured out the O(n) solution, try coding another solution using the divide and conquer approach, which is more subtle.
- - - ## Solutions - ### **Python3** @@ -50,8 +39,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/16.18.Pattern Matching/README.md b/lcci/16.18.Pattern Matching/README.md index fecbbabe319e4..7785db6d2b738 100644 --- a/lcci/16.18.Pattern Matching/README.md +++ b/lcci/16.18.Pattern Matching/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/16.18.Pattern%20Matching/README_EN.md) ## 题目描述 +你有两个字符串,即pattern
和value
。 pattern
字符串由字母"a"
和"b"
组成,用于描述字符串中的模式。例如,字符串"catcatgocatgo"
匹配模式"aabab"
(其中"cat"
是"a"
,"go"
是"b"
),该字符串也匹配像"a"
、"ab"
和"b"
这样的模式。但需注意"a"
和"b"
不能同时表示相同的字符串。编写一个方法判断value
字符串是否匹配pattern
字符串。
示例 1:
@@ -29,14 +30,14 @@pattern
只包含字母"a"
和"b"
,value
仅包含小写字母。You are given two strings, pattern and value. The pattern string consists of just the letters a and b, describing a pattern within a string. For example, the string catcatgocatgo matches the pattern aabab (where cat is a and go is b). It also matches patterns like a, ab, and b. Write a method to determine if value matches pattern. a and b cannot be the same string.
- +You are given two strings, pattern and value. The pattern string consists of just the letters a and b, describing a pattern within a string. For example, the string catcatgocatgo matches the pattern aabab (where cat is a and go is b). It also matches patterns like a, ab, and b. Write a method to determine if value matches pattern. a and b cannot be the same string.
Example 1:
- -Input: pattern = "abba", value = "dogcatcatdog" @@ -19,12 +16,8 @@- -
Example 2:
- -Input: pattern = "abba", value = "dogcatcatfish" @@ -33,12 +26,8 @@- -
Example 3:
- -Input: pattern = "aaaa", value = "dogcatcatdog" @@ -47,12 +36,8 @@- -
Example 4:
- -Input: pattern = "abba", value = "dogdogdogdog" @@ -63,24 +48,16 @@- -
Note:
- -0 <= len(pattern) <= 1000
0 <= len(value) <= 1000
pattern
only contains "a"
and "b"
, value
only contains lowercase letters.你有一个用于表示一片土地的整数矩阵land
,该矩阵中每个点的值代表对应地点的海拔高度。若值为0则表示水域。由垂直、水平或对角连接的水域为池塘。池塘的大小是指相连接的水域的个数。编写一个方法来计算矩阵中所有池塘的大小,返回值需要从小到大排序。
示例:
@@ -21,14 +22,14 @@0 < len(land[i]) <= 1000
You have an integer matrix representing a plot of land, where the value at that location represents the height above sea level. A value of zero indicates water. A pond is a region of water connected vertically, horizontally, or diagonally. The size of the pond is the total number of connected water cells. Write a method to compute the sizes of all ponds in the matrix.
- +You have an integer matrix representing a plot of land, where the value at that location represents the height above sea level. A value of zero indicates water. A pond is a region of water connected vertically, horizontally, or diagonally. The size of the pond is the total number of connected water cells. Write a method to compute the sizes of all ponds in the matrix.
Example:
- -Input: @@ -31,23 +28,15 @@- -
Note:
- -0 < len(land) <= 1000
0 < len(land[i]) <= 1000
在老式手机上,用户通过数字键盘输入,手机将提供与这些数字相匹配的单词列表。每个数字映射到0至4个字母。给定一个数字序列,实现一个算法来返回匹配单词的列表。你会得到一张含有有效单词的列表。映射如下图所示:
@@ -28,14 +29,14 @@num
中不会出现 0, 1 这两个数字On old cell phones, users typed on a numeric keypad and the phone would provide a list of words that matched these numbers. Each digit mapped to a set of 0 - 4 letters. Implement an algorithm to return a list of matching words, given a sequence of digits. You are provided a list of valid words. The mapping is shown in the diagram below:
 -Example 1:
- -Input: num = "8733", words = ["tree", "used"] @@ -20,24 +18,16 @@- -
Example 2:
- -Input: num = "2", words = ["a", "b", "c", "d"] Output: ["a", "b", "c"]- -
Note:
- -num.length <= 1000
words.length <= 500
There are no number 0 and 1 in num
.给定两个整数数组,请交换一对数值(每个数组中取一个数值),使得两个数组所有元素的和相等。
@@ -25,14 +26,16 @@1 <= array1.length, array2.length <= 100000
Given two arrays of integers, find a pair of values (one value from each array) that you can swap to give the two arrays the same sum.
- +Given two arrays of integers, find a pair of values (one value from each array) that you can swap to give the two arrays the same sum.
Return an array, where the first element is the element in the first array that will be swapped, and the second element is another one in the second array. If there are more than one answers, return any one of them. If there is no answer, return an empty array.
- -Example:
- -Input: array1 = [4, 1, 2, 1, 1, 2], array2 = [3, 6, 3, 3] @@ -23,34 +18,22 @@- -
Example:
- -
Input: array1 = [1, 2, 3], array2 = [4, 5, 6]
Output: []
-
-
Note:
- -1 <= array1.length, array2.length <= 100000
一只蚂蚁坐在由白色和黑色方格构成的无限网格上。开始时,网格全白,蚂蚁面向右侧。每行走一步,蚂蚁执行以下操作。
@@ -46,14 +47,14 @@K <= 100000
An ant is sitting on an infinite grid of white and black squares. It initially faces right. All squares are white initially.
- +An ant is sitting on an infinite grid of white and black squares. It initially faces right. All squares are white initially.
At each step, it does the following:
- -(1) At a white square, flip the color of the square, turn 90 degrees right (clockwise), and move forward one unit.
- -(2) At a black square, flip the color of the square, turn 90 degrees left (counter-clockwise), and move forward one unit.
- -Write a program to simulate the first K moves that the ant makes and print the final board as a grid.
- -The grid should be represented as an array of strings, where each element represents one row in the grid. The black square is represented as 'X'
, and the white square is represented as '_'
, the square which is occupied by the ant is represented as 'L'
, 'U'
, 'R'
, 'D'
, which means the left, up, right and down orientations respectively. You only need to return the minimum matrix that is able to contain all squares that are passed through by the ant.
Example 1:
- -Input: 0 @@ -39,12 +26,8 @@- -
Example 2:
- -Input: 2 @@ -61,12 +44,8 @@- -
Example 3:
- -Input: 5 @@ -85,22 +64,14 @@- -
Note:
- -K <= 100000
设计一个算法,找出数组中两数之和为指定值的所有整数对。一个数只能属于一个数对。
@@ -22,14 +23,14 @@nums.length <= 100000
Design an algorithm to find all pairs of integers within an array which sum to a specified value.
- +Design an algorithm to find all pairs of integers within an array which sum to a specified value.
Example 1:
- -Input: nums = [5,6,5], target = 11 Output: [[5,6]]- -
Example 2:
- -Input: nums = [5,6,5,6], target = 11 Output: [[5,6],[5,6]]- -
Note:
- -nums.length <= 100000
设计和构建一个“最近最少使用”缓存,该缓存会删除最近最少使用的项目。缓存应该从键映射到值(允许你插入和检索特定键对应的值),并在初始化时指定最大容量。当缓存被填满时,它应该删除最近最少使用的项目。
@@ -26,14 +27,14 @@ cache.get(3); // 返回 3 cache.get(4); // 返回 4 - ## 解法 - + ### **Python3** + ```python @@ -41,6 +42,7 @@ cache.get(4); // 返回 4 ``` ### **Java** + ```java @@ -48,8 +50,9 @@ cache.get(4); // 返回 4 ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/16.25.LRU Cache/README_EN.md b/lcci/16.25.LRU Cache/README_EN.md index 461043d6331d3..f48cae9f301b6 100644 --- a/lcci/16.25.LRU Cache/README_EN.md +++ b/lcci/16.25.LRU Cache/README_EN.md @@ -3,24 +3,17 @@ [中文文档](/lcci/16.25.LRU%20Cache/README.md) ## Description -Design and build a "least recently used" cache, which evicts the least recently used item. The cache should map from keys to values (allowing you to insert and retrieve a value associated with a particular key) and be initialized with a max size. When it is full, it should evict the least recently used item.
- +Design and build a "least recently used" cache, which evicts the least recently used item. The cache should map from keys to values (allowing you to insert and retrieve a value associated with a particular key) and be initialized with a max size. When it is full, it should evict the least recently used item.
You should implement following operations: get
and put
.
Get a value by key: get(key)
- If key is in the cache, return the value, otherwise return -1.
Write a key-value pair to the cache: put(key, value)
- If the key is not in the cache, then write its value to the cache. Evict the least recently used item before writing if necessary.
Example:
- -LRUCache cache = new LRUCache( 2 /* capacity */ ); @@ -47,12 +40,8 @@ cache.get(4); // returns 4- - - ## Solutions - ### **Python3** @@ -68,8 +57,9 @@ cache.get(4); // returns 4 ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/16.26.Calculator/README.md b/lcci/16.26.Calculator/README.md index 5b0c6162675d2..ee6e9bd9e921c 100644 --- a/lcci/16.26.Calculator/README.md +++ b/lcci/16.26.Calculator/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/16.26.Calculator/README_EN.md) ## 题目描述 +
给定一个包含正整数、加(+)、减(-)、乘(*)、除(/)的算数表达式(括号除外),计算其结果。
@@ -32,14 +33,14 @@eval
。Given an arithmetic equation consisting of positive integers, +, -, * and / (no parentheses), compute the result.
- +Given an arithmetic equation consisting of positive integers, +, -, * and / (no parentheses), compute the result.
The expression string contains only non-negative integers, +, -, *, / operators and empty spaces . The integer division should truncate toward zero.
- -Example 1:
- -Input: "3+2*2" @@ -23,24 +18,16 @@- -
Example 2:
- -Input: " 3/2 " Output: 1- -
Example 3:
- -Input: " 3+5 / 2 " @@ -49,23 +36,15 @@- -
Note:
- -设计一个函数把两个数字相加。不得使用 + 或者其他算术运算符。
@@ -20,14 +21,14 @@Write a function that adds two numbers. You should not use + or any arithmetic operators.
- +Write a function that adds two numbers. You should not use + or any arithmetic operators.
Example:
- -Input: a = 1, b = 1 Output: 2- -
- -
Note:
- -a
and b
may be 0 or negative.数组nums
包含从0
到n
的所有整数,但其中缺了一个。请编写代码找出那个缺失的整数。你有办法在O(n)时间内完成吗?
An array contains all the integers from 0 to n, except for one number which is missing. Write code to find the missing integer. Can you do it in O(n) time?
- +An array contains all the integers from 0 to n, except for one number which is missing. Write code to find the missing integer. Can you do it in O(n) time?
Note: This problem is slightly different from the original one the book.
- -Example 1:
- -Input: [3,0,1] Output: 2- -
- -
Example 2:
- -Input: [9,6,4,2,3,5,7,0,1] @@ -39,12 +28,8 @@- - - ## Solutions - ### **Python3** @@ -77,8 +62,9 @@ class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/17.05.Find Longest Subarray/README.md b/lcci/17.05.Find Longest Subarray/README.md index bc990ea123761..ccc1c9bbd1a89 100644 --- a/lcci/17.05.Find Longest Subarray/README.md +++ b/lcci/17.05.Find Longest Subarray/README.md @@ -1,8 +1,9 @@ -# [面试题 17.05. 字母与数字](https://leetcode-cn.com/problems/find-longest-subarray-lcci) +# [面试题 17.05. 字母与数字](https://leetcode-cn.com/problems/find-longest-subarray-lcci) [English Version](/lcci/17.05.Find%20Longest%20Subarray/README_EN.md) ## 题目描述 +
给定一个放有字符和数字的数组,找到最长的子数组,且包含的字符和数字的个数相同。
@@ -28,14 +29,14 @@array.length <= 100000
Given an array filled with letters and numbers, find the longest subarray with an equal number of letters and numbers.
- +Given an array filled with letters and numbers, find the longest subarray with an equal number of letters and numbers.
Return the subarray. If there are more than one answer, return the one which has the smallest index of its left endpoint. If there is no answer, return an empty arrary.
- -Example 1:
- -Input: ["A","1","B","C","D","2","3","4","E","5","F","G","6","7","H","I","J","K","L","M"] @@ -25,12 +20,8 @@- -
Example 2:
- -Input: ["A","A"] @@ -41,22 +32,14 @@- -
Note:
- -array.length <= 100000
编写一个方法,计算从 0 到 n (含 n) 中数字 2 出现的次数。
@@ -18,14 +19,14 @@n <= 10^9
Write a method to count the number of 2s that appear in all the numbers between 0 and n (inclusive).
- +Write a method to count the number of 2s that appear in all the numbers between 0 and n (inclusive).
Example:
- -Input: 25 @@ -19,22 +16,14 @@ Explanation: (2, 12, 20, 21, 22, 23, 24, 25)(Note that 22 counts for two 2s.)- -
Note:
- -n <= 10^9
每年,政府都会公布一万个最常见的婴儿名字和它们出现的频率,也就是同名婴儿的数量。有些名字有多种拼法,例如,John 和 Jon 本质上是相同的名字,但被当成了两个名字公布出来。给定两个列表,一个是名字及对应的频率,另一个是本质相同的名字对。设计一个算法打印出每个真实名字的实际频率。注意,如果 John 和 Jon 是相同的,并且 Jon 和 Johnny 相同,则 John 与 Johnny 也相同,即它们有传递和对称性。
@@ -19,14 +20,14 @@names.length <= 100000
Each year, the government releases a list of the 10000 most common baby names and their frequencies (the number of babies with that name). The only problem with this is that some names have multiple spellings. For example,"John" and ''Jon" are essentially the same name but would be listed separately in the list. Given two lists, one of names/frequencies and the other of pairs of equivalent names, write an algorithm to print a new list of the true frequency of each name. Note that if John and Jon are synonyms, and Jon and Johnny are synonyms, then John and Johnny are synonyms. (It is both transitive and symmetric.) In the final list, choose the name that are lexicographically smallest as the "real" name.
- +Each year, the government releases a list of the 10000 most common baby names and their frequencies (the number of babies with that name). The only problem with this is that some names have multiple spellings. For example,"John" and ''Jon" are essentially the same name but would be listed separately in the list. Given two lists, one of names/frequencies and the other of pairs of equivalent names, write an algorithm to print a new list of the true frequency of each name. Note that if John and Jon are synonyms, and Jon and Johnny are synonyms, then John and Johnny are synonyms. (It is both transitive and symmetric.) In the final list, choose the name that are lexicographically smallest as the "real" name.
Example:
- -Input: names = ["John(15)","Jon(12)","Chris(13)","Kris(4)","Christopher(19)"], synonyms = ["(Jon,John)","(John,Johnny)","(Chris,Kris)","(Chris,Christopher)"] Output: ["John(27)","Chris(36)"]- -
Note:
- -names.length <= 100000
有个马戏团正在设计叠罗汉的表演节目,一个人要站在另一人的肩膀上。出于实际和美观的考虑,在上面的人要比下面的人矮一点且轻一点。已知马戏团每个人的身高和体重,请编写代码计算叠罗汉最多能叠几个人。
@@ -18,14 +19,14 @@height.length == weight.length <= 10000
A circus is designing a tower routine consisting of people standing atop one another's shoulders. For practical and aesthetic reasons, each person must be both shorter and lighter than the person below him or her. Given the heights and weights of each person in the circus, write a method to compute the largest possible number of people in such a tower.
- +A circus is designing a tower routine consisting of people standing atop one another's shoulders. For practical and aesthetic reasons, each person must be both shorter and lighter than the person below him or her. Given the heights and weights of each person in the circus, write a method to compute the largest possible number of people in such a tower.
Example:
- -Input: height = [65,70,56,75,60,68] weight = [100,150,90,190,95,110] @@ -19,22 +16,14 @@ Explanation: The longest tower is length 6 and includes from top to bottom: (56,90), (60,95), (65,100), (68,110), (70,150), (75,190)- -
Note:
- -height.length == weight.length <= 10000
有些数的素因子只有 3,5,7,请设计一个算法找出第 k 个数。注意,不是必须有这些素因子,而是必须不包含其他的素因子。例如,前几个数按顺序应该是 1,3,5,7,9,15,21。
@@ -13,14 +14,14 @@ 输出: 9 - ## 解法 - + ### **Python3** + ```python @@ -28,6 +29,7 @@ ``` ### **Java** + ```java @@ -35,8 +37,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/17.09.Get Kth Magic Number/README_EN.md b/lcci/17.09.Get Kth Magic Number/README_EN.md index de2115da6bbd3..320a1b81aec3e 100644 --- a/lcci/17.09.Get Kth Magic Number/README_EN.md +++ b/lcci/17.09.Get Kth Magic Number/README_EN.md @@ -1,14 +1,11 @@ # [17.09. Get Kth Magic Number](https://leetcode-cn.com/problems/get-kth-magic-number-lcci) ## Description -Design an algorithm to find the kth number such that the only prime factors are 3, 5, and 7. Note that 3, 5, and 7 do not have to be factors, but it should not have any other prime factors. For example, the first several multiples would be (in order) 1, 3, 5, 7, 9, 15, 21.
- +Design an algorithm to find the kth number such that the only prime factors are 3, 5, and 7. Note that 3, 5, and 7 do not have to be factors, but it should not have any other prime factors. For example, the first several multiples would be (in order) 1, 3, 5, 7, 9, 15, 21.
Example 1:
- -Input: k = 5 @@ -19,12 +16,8 @@- - - ## Solutions - ### **Python3** @@ -40,8 +33,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/17.10.Find Majority Element/README.md b/lcci/17.10.Find Majority Element/README.md index 3b8f16f5ca16a..ad1805f1708ba 100644 --- a/lcci/17.10.Find Majority Element/README.md +++ b/lcci/17.10.Find Majority Element/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/17.10.Find%20Majority%20Element/README_EN.md) ## 题目描述 +
如果数组中多一半的数都是同一个,则称之为主要元素。给定一个整数数组,找到它的主要元素。若没有,返回-1。
@@ -30,14 +31,14 @@说明:
你有办法在时间复杂度为 O(N),空间复杂度为 O(1) 内完成吗?
A majority element is an element that makes up more than half of the items in an array. Given a positive integers array, find the majority element. If there is no majority element, return -1. Do this in O(N) time and O(1) space.
- +A majority element is an element that makes up more than half of the items in an array. Given a positive integers array, find the majority element. If there is no majority element, return -1. Do this in O(N) time and O(1) space.
Example 1:
- -Input: [1,2,5,9,5,9,5,5,5] Output: 5- -
- -
Example 2:
- -Input: [3,2] Output: -1- -
- -
Example 3:
- -Input: [2,2,1,1,1,2,2] @@ -51,12 +36,8 @@- - - ## Solutions - ### **Python3** @@ -72,8 +53,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/17.11.Find Closest/README.md b/lcci/17.11.Find Closest/README.md index 6146366881fa5..c71e3acdf86b1 100644 --- a/lcci/17.11.Find Closest/README.md +++ b/lcci/17.11.Find Closest/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/17.11.Find%20Closest/README_EN.md) ## 题目描述 +
有个内含单词的超大文本文件,给定任意两个单词,找出在这个文件中这两个单词的最短距离(相隔单词数)。如果寻找过程在这个文件中会重复多次,而每次寻找的单词不同,你能对此优化吗?
@@ -17,14 +18,14 @@words.length <= 100000
You have a large text file containing words. Given any two words, find the shortest distance (in terms of number of words) between them in the file. If the operation will be repeated many times for the same file (but different pairs of words), can you optimize your solution?
- +You have a large text file containing words. Given any two words, find the shortest distance (in terms of number of words) between them in the file. If the operation will be repeated many times for the same file (but different pairs of words), can you optimize your solution?
Example:
- -Input: words = ["I","am","a","student","from","a","university","in","a","city"], word1 = "a", word2 = "student" Output: 1- -
Note:
-words.length <= 100000
二叉树数据结构TreeNode
可用来表示单向链表(其中left
置空,right
为下一个链表节点)。实现一个方法,把二叉搜索树转换为单向链表,要求值的顺序保持不变,转换操作应是原址的,也就是在原始的二叉搜索树上直接修改。
The data structure TreeNode
is used for binary tree, but it can also used to represent a single linked list (where left is null, and right is the next node in the list). Implement a method to convert a binary search tree (implemented with TreeNode
) into a single linked list. The values should be kept in order and the operation should be performed in place (that is, on the original data structure).
The data structure TreeNode
is used for binary tree, but it can also used to represent a single linked list (where left is null, and right is the next node in the list). Implement a method to convert a binary search tree (implemented with TreeNode
) into a single linked list. The values should be kept in order and the operation should be performed in place (that is, on the original data structure).
Return the head node of the linked list after converting.
- -Note: This problem is slightly different from the original one in the book.
- -- -
Example:
- -Input: [4,2,5,1,3,null,6,0] @@ -31,22 +22,14 @@- -
Note:
- -哦,不!你不小心把一个长篇文章中的空格、标点都删掉了,并且大写也弄成了小写。像句子"I reset the computer. It still didn’t boot!"
已经变成了"iresetthecomputeritstilldidntboot"
。在处理标点符号和大小写之前,你得先把它断成词语。当然了,你有一本厚厚的词典dictionary
,不过,有些词没在词典里。假设文章用sentence
表示,设计一个算法,把文章断开,要求未识别的字符最少,返回未识别的字符数。
dictionary
和sentence
中只包含小写字母。Oh, no! You have accidentally removed all spaces, punctuation, and capitalization in a lengthy document. A sentence like "I reset the computer. It still didn't boot!" became "iresetthecomputeritstilldidntboot''. You'll deal with the punctuation and capitalization later; right now you need to re-insert the spaces. Most of the words are in a dictionary but a few are not. Given a dictionary (a list of strings) and the document (a string), design an algorithm to unconcatenate the document in a way that minimizes the number of unrecognized characters. Return the number of unrecognized characters.
- +Oh, no! You have accidentally removed all spaces, punctuation, and capitalization in a lengthy document. A sentence like "I reset the computer. It still didn't boot!" became "iresetthecomputeritstilldidntboot''. You'll deal with the punctuation and capitalization later; right now you need to re-insert the spaces. Most of the words are in a dictionary but a few are not. Given a dictionary (a list of strings) and the document (a string), design an algorithm to unconcatenate the document in a way that minimizes the number of unrecognized characters. Return the number of unrecognized characters.
Note: This problem is slightly different from the original one in the book.
- -- -
Example:
- -Input: @@ -33,24 +26,16 @@ sentence = "jesslookedjustliketimherbrother"- -
Note:
- -0 <= len(sentence) <= 1000
The total number of characters in dictionary
is less than or equal to 150000.dictionary
and sentence
.设计一个算法,找出数组中最小的k个数。以任意顺序返回这k个数均可。
@@ -19,14 +20,14 @@0 <= k <= min(100000, len(arr))
Design an algorithm to find the smallest K numbers in an array.
- +Design an algorithm to find the smallest K numbers in an array.
Example:
- -Input: arr = [1,3,5,7,2,4,6,8], k = 4 @@ -19,23 +16,15 @@- -
Note:
- -0 <= len(arr) <= 100000
0 <= k <= min(100000, len(arr))
给定一组单词words
,编写一个程序,找出其中的最长单词,且该单词由这组单词中的其他单词组合而成。若有多个长度相同的结果,返回其中字典序最小的一项,若没有符合要求的单词则返回空字符串。
示例:
@@ -16,14 +17,14 @@1 <= len(words[i]) <= 100
Given a list of words, write a program to find the longest word made of other words in the list. If there are more than one answer, return the one that has smallest lexicographic order. If no answer, return an empty string.
- +Given a list of words, write a program to find the longest word made of other words in the list. If there are more than one answer, return the one that has smallest lexicographic order. If no answer, return an empty string.
Example:
- -Input: ["cat","banana","dog","nana","walk","walker","dogwalker"] @@ -21,23 +18,15 @@- -
Note:
- -0 <= len(words) <= 100
1 <= len(words[i]) <= 100
一个有名的按摩师会收到源源不断的预约请求,每个预约都可以选择接或不接。在每次预约服务之间要有休息时间,因此她不能接受相邻的预约。给定一个预约请求序列,替按摩师找到最优的预约集合(总预约时间最长),返回总的分钟数。
@@ -31,15 +32,16 @@ 解释: 选择 1 号预约、 3 号预约、 5 号预约和 8 号预约,总时长 = 2 + 4 + 3 + 3 = 12。 - ## 解法 + -递推求解。 +递推求解。 ### **Python3** + ```python @@ -59,6 +61,7 @@ class Solution: ``` ### **Java** + ```java @@ -84,8 +87,9 @@ class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/17.16.The Masseuse/README_EN.md b/lcci/17.16.The Masseuse/README_EN.md index 99bc5617ae7f8..b296f4fc5f46f 100644 --- a/lcci/17.16.The Masseuse/README_EN.md +++ b/lcci/17.16.The Masseuse/README_EN.md @@ -3,22 +3,15 @@ [中文文档](/lcci/17.16.The%20Masseuse/README.md) ## Description -A popular masseuse receives a sequence of back-to-back appointment requests and is debating which ones to accept. She needs a break between appointments and therefore she cannot accept any adjacent requests. Given a sequence of back-to-back appoint ment requests, find the optimal (highest total booked minutes) set the masseuse can honor. Return the number of minutes.
- +A popular masseuse receives a sequence of back-to-back appointment requests and is debating which ones to accept. She needs a break between appointments and therefore she cannot accept any adjacent requests. Given a sequence of back-to-back appoint ment requests, find the optimal (highest total booked minutes) set the masseuse can honor. Return the number of minutes.
Note: This problem is slightly different from the original one in the book.
- -- -
Example 1:
- -Input: [1,2,3,1] @@ -29,12 +22,8 @@- -
Example 2:
- -Input: [2,7,9,3,1] @@ -45,12 +34,8 @@- -
Example 3:
- -Input: [2,1,4,5,3,1,1,3] @@ -61,12 +46,8 @@- - - ## Solutions - ### **Python3** @@ -112,8 +93,9 @@ class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/17.17.Multi Search/README.md b/lcci/17.17.Multi Search/README.md index da47994efa2b6..0b0b2dd563fce 100644 --- a/lcci/17.17.Multi Search/README.md +++ b/lcci/17.17.Multi Search/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/17.17.Multi%20Search/README_EN.md) ## 题目描述 +
给定一个较长字符串big
和一个包含较短字符串的数组smalls
,设计一个方法,根据smalls
中的每一个较短字符串,对big
进行搜索。输出smalls
中的字符串在big
里出现的所有位置positions
,其中positions[i]
为smalls[i]
出现的所有位置。
Given a string band an array of smaller strings T, design a method to search b for each small string in T. Output positions
of all strings in smalls
that appear in big
, where positions[i]
is all positions of smalls[i]
.
Given a string band an array of smaller strings T, design a method to search b for each small string in T. Output positions
of all strings in smalls
that appear in big
, where positions[i]
is all positions of smalls[i]
.
Example:
- -Input: @@ -23,12 +20,8 @@ smalls = ["is","ppi","hi","sis","i&- -
Note:
- -0 <= len(big) <= 1000
0 <= len(smalls[i]) <= 1000
假设你有两个数组,一个长一个短,短的元素均不相同。找到长数组中包含短数组所有的元素的最短子数组,其出现顺序无关紧要。
@@ -29,14 +30,14 @@ small = [4]1 <= small.length <= 100000
You are given two arrays, one shorter (with all distinct elements) and one longer. Find the shortest subarray in the longer array that contains all the elements in the shorter array. The items can appear in any order.
- +You are given two arrays, one shorter (with all distinct elements) and one longer. Find the shortest subarray in the longer array that contains all the elements in the shorter array. The items can appear in any order.
Return the indexes of the leftmost and the rightmost elements of the array. If there are more than one answer, return the one that has the smallest left index. If there is no answer, return an empty array.
- -Example 1:
- -Input: @@ -25,12 +20,8 @@ small = [1,5,9] Output: [7,10]- -
Example 2:
- -Input: @@ -41,23 +32,15 @@ small = [4] Output: []- -
Note:
- -big.length <= 100000
1 <= small.length <= 100000
给定一个数组,包含从 1 到 N 所有的整数,但其中缺了两个数字。你能在 O(N) 时间内只用 O(1) 的空间找到它们吗?
@@ -24,14 +25,16 @@nums.length <= 30000
You are given an array with all the numbers from 1 to N appearing exactly once, except for two number that is missing. How can you find the missing number in O(N) time and 0(1) space?
- +You are given an array with all the numbers from 1 to N appearing exactly once, except for two number that is missing. How can you find the missing number in O(N) time and 0(1) space?
You can return the missing numbers in any order.
- -Example 1:
- -
Input: [1]
Output: [2,3]
-
-
Example 2:
- -
Input: [2,3]
Output: [1,4]
-
-
Note:
- -nums.length <= 30000
随机产生数字并传递给一个方法。你能否完成这个方法,在每次产生新值时,寻找当前所有值的中间值(中位数)并保存。
@@ -30,16 +31,18 @@ addNum(3) findMedian() -> 2 - ## 解法 + + - 创建大根堆、小根堆,其中:大根堆存放较小的一半元素,小根堆存放较大的一半元素。 -- 添加元素时,若两堆元素个数相等,放入小根堆(使得小根堆个数多1);若不等,放入大根堆(使得大小根堆元素个数相等) +- 添加元素时,若两堆元素个数相等,放入小根堆(使得小根堆个数多 1);若不等,放入大根堆(使得大小根堆元素个数相等) - 取中位数时,若两堆元素个数相等,取两堆顶求平均值;若不等,取小根堆堆顶。 ### **Python3** + ```python @@ -70,6 +73,7 @@ class MedianFinder: ``` ### **Java** + ```java @@ -82,7 +86,7 @@ class MedianFinder { minHeap = new PriorityQueue<>(); maxHeap = new PriorityQueue<>((a, b) -> b - a); } - + public void addNum(int num) { if (minHeap.size() == maxHeap.size()) { maxHeap.offer(num); @@ -92,7 +96,7 @@ class MedianFinder { maxHeap.offer(minHeap.poll()); } } - + public double findMedian() { return minHeap.size() == maxHeap.size() ? (minHeap.peek() + maxHeap.peek()) / 2.0 : minHeap.peek(); } @@ -107,8 +111,9 @@ class MedianFinder { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/17.20.Continuous Median/README_EN.md b/lcci/17.20.Continuous Median/README_EN.md index 5afb8a27575f2..5d7b85c5bac53 100644 --- a/lcci/17.20.Continuous Median/README_EN.md +++ b/lcci/17.20.Continuous Median/README_EN.md @@ -3,41 +3,26 @@ [中文文档](/lcci/17.20.Continuous%20Median/README.md) ## Description -Numbers are randomly generated and passed to a method. Write a program to find and maintain the median value as new values are generated.
- +Numbers are randomly generated and passed to a method. Write a program to find and maintain the median value as new values are generated.
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.
- -For example,
- -[2,3,4], the median is 3
- -[2,3], the median is (2 + 3) / 2 = 2.5
- -Design a data structure that supports the following two operations:
- -Example:
- -addNum(1) @@ -52,12 +37,8 @@ findMedian() -> 2- - - ## Solutions - ### **Python3** @@ -101,7 +82,7 @@ class MedianFinder { minHeap = new PriorityQueue<>(); maxHeap = new PriorityQueue<>((a, b) -> b - a); } - + public void addNum(int num) { if (minHeap.size() == maxHeap.size()) { maxHeap.offer(num); @@ -111,7 +92,7 @@ class MedianFinder { maxHeap.offer(minHeap.poll()); } } - + public double findMedian() { return minHeap.size() == maxHeap.size() ? (minHeap.peek() + maxHeap.peek()) / 2.0 : minHeap.peek(); } @@ -126,8 +107,9 @@ class MedianFinder { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/17.21.Volume of Histogram/README.md b/lcci/17.21.Volume of Histogram/README.md index e014090bc8125..a54c1fba58720 100644 --- a/lcci/17.21.Volume of Histogram/README.md +++ b/lcci/17.21.Volume of Histogram/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/17.21.Volume%20of%20Histogram/README_EN.md) ## 题目描述 +
给定一个直方图(也称柱状图),假设有人从上面源源不断地倒水,最后直方图能存多少水量?直方图的宽度为 1。
@@ -15,14 +16,14 @@输入: [0,1,0,2,1,0,1,3,2,1,2,1] 输出: 6- ## 解法 - + ### **Python3** + ```python @@ -30,6 +31,7 @@ ``` ### **Java** + ```java @@ -37,8 +39,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/17.21.Volume of Histogram/README_EN.md b/lcci/17.21.Volume of Histogram/README_EN.md index 5cdaf874145fd..1e1bc93fe1862 100644 --- a/lcci/17.21.Volume of Histogram/README_EN.md +++ b/lcci/17.21.Volume of Histogram/README_EN.md @@ -3,34 +3,23 @@ [中文文档](/lcci/17.21.Volume%20of%20Histogram/README.md) ## Description -
Imagine a histogram (bar graph). Design an algorithm to compute the volume of water it could hold if someone poured water across the top. You can assume that each histogram bar has width 1.
- +Imagine a histogram (bar graph). Design an algorithm to compute the volume of water it could hold if someone poured water across the top. You can assume that each histogram bar has width 1.
 - -The above elevation map is represented by array [0,1,0,2,1,0,1,3,2,1,2,1]. In this case, 6 units of water (blue section) are being trapped. Thanks Marcos for contributing this image!
- -Example:
- -Input: [0,1,0,2,1,0,1,3,2,1,2,1] Output: 6- - - ## Solutions - ### **Python3** @@ -46,8 +35,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/17.22.Word Transformer/README.md b/lcci/17.22.Word Transformer/README.md index a265bd153eabc..d721b88f08cfc 100644 --- a/lcci/17.22.Word Transformer/README.md +++ b/lcci/17.22.Word Transformer/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/17.22.Word%20Transformer/README_EN.md) ## 题目描述 +
给定字典中的两个词,长度相等。写一个方法,把一个词转换成另一个词, 但是一次只能改变一个字符。每一步得到的新词都必须能在字典中找到。
@@ -30,14 +31,14 @@ wordList = ["hot","dot","dog","lot",&quo 解释: endWord "cog" 不在字典中,所以不存在符合要求的转换序列。 - ## 解法 - + ### **Python3** + ```python @@ -45,6 +46,7 @@ wordList = ["hot","dot","dog","lot",&quo ``` ### **Java** + ```java @@ -52,8 +54,9 @@ wordList = ["hot","dot","dog","lot",&quo ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/17.22.Word Transformer/README_EN.md b/lcci/17.22.Word Transformer/README_EN.md index 6a0abb6f73cf0..77f9ead091abe 100644 --- a/lcci/17.22.Word Transformer/README_EN.md +++ b/lcci/17.22.Word Transformer/README_EN.md @@ -3,18 +3,13 @@ [中文文档](/lcci/17.22.Word%20Transformer/README.md) ## Description -Given two words of equal length that are in a dictionary, write a method to transform one word into another word by changing only one letter at a time. The new word you get in each step must be in the dictionary.
- +Given two words of equal length that are in a dictionary, write a method to transform one word into another word by changing only one letter at a time. The new word you get in each step must be in the dictionary.
Write code to return a possible transforming sequence. If there are more that one sequence, any one is ok.
- -Example 1:
- -Input: @@ -33,12 +28,8 @@ wordList = ["hot","dot","dog","lot",&quo- -
Example 2:
- -Input: @@ -57,12 +48,8 @@ wordList = ["hot","dot","dog","lot",&quo Explanation: endWord "cog" is not in the dictionary, so there's no possible transforming sequence.- - - ## Solutions - ### **Python3** @@ -78,8 +65,9 @@ wordList = ["hot","dot","dog","lot",&quo ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/lcci/17.23.Max Black Square/README.md b/lcci/17.23.Max Black Square/README.md index 094a675ee954b..a3e26a3ebf265 100644 --- a/lcci/17.23.Max Black Square/README.md +++ b/lcci/17.23.Max Black Square/README.md @@ -3,6 +3,7 @@ [English Version](/lcci/17.23.Max%20Black%20Square/README_EN.md) ## 题目描述 +
给定一个方阵,其中每个单元(像素)非黑即白。设计一个算法,找出 4 条边皆为黑色像素的最大子方阵。
@@ -37,14 +38,14 @@matrix.length == matrix[0].length <= 200
Imagine you have a square matrix, where each cell (pixel) is either black or white Design an algorithm to find the maximum subsquare such that all four borders are filled with black pixels.
- +Imagine you have a square matrix, where each cell (pixel) is either black or white Design an algorithm to find the maximum subsquare such that all four borders are filled with black pixels.
Return an array [r, c, size]
, where r
, c
are the row number and the column number of the subsquare's upper left corner respectively, and size
is the side length of the subsquare. If there are more than one answers, return the one that has smallest r
. If there are more than one answers that have the same r
, return the one that has smallest c
. If there's no answer, return an empty array.
Example 1:
- -Input: @@ -35,12 +30,8 @@- -
Example 2:
- -Input: @@ -59,22 +50,14 @@- -
Note:
- -matrix.length == matrix[0].length <= 200
给定一个正整数和负整数组成的 N × M 矩阵,编写代码找出元素总和最大的子矩阵。
@@ -26,14 +27,14 @@1 <= matrix.length, matrix[0].length <= 200
Given an NxN matrix of positive and negative integers, write code to find the submatrix with the largest possible sum.
- +Given an NxN matrix of positive and negative integers, write code to find the submatrix with the largest possible sum.
Return an array [r1, c1, r2, c2]
, where r1
, c1
are the row number and the column number of the submatrix's upper left corner respectively, and r2
, c2
are the row number of and the column number of lower right corner. If there are more than one answers, return any one of them.
Note: This problem is slightly different from the original one in the book.
- -Example:
- -Input: @@ -33,22 +26,14 @@ Output: [0,1,0,1]- -
Note:
- -1 <= matrix.length, matrix[0].length <= 200
给定一份单词的清单,设计一个算法,创建由字母组成的面积最大的矩形,其中每一行组成一个单词(自左向右),每一列也组成一个单词(自上而下)。不要求这些单词在清单里连续出现,但要求所有行等长,所有列等高。
@@ -31,14 +32,14 @@Given a list of millions of words, design an algorithm to create the largest possible rectangle of letters such that every row forms a word (reading left to right) and every column forms a word (reading top to bottom). The words need not be chosen consecutively from the list but all rows must be the same length and all columns must be the same height.
- +Given a list of millions of words, design an algorithm to create the largest possible rectangle of letters such that every row forms a word (reading left to right) and every column forms a word (reading top to bottom). The words need not be chosen consecutively from the list but all rows must be the same length and all columns must be the same height.
If there are more than one answer, return any one of them. A word can be used more than once.
- -Example 1:
- -
Input: ["this", "real", "hard", "trh", "hea", "iar", "sld"]
@@ -31,36 +26,24 @@
]
-
-
Example 2:
- -
Input: ["aa"]
Output: ["aa","aa"]
-
-
Notes:
- -words.length <= 1000
words[i].length <= 100
两个(具有不同单词的)文档的交集(intersection)中元素的个数除以并集(union)中元素的个数,就是这两个文档的相似度。例如,{1, 5, 3} 和 {1, 7, 2, 3} 的相似度是 0.4,其中,交集的元素有 2 个,并集的元素有 5 个。给定一系列的长篇文档,每个文档元素各不相同,并与一个 ID 相关联。它们的相似度非常“稀疏”,也就是说任选 2 个文档,相似度都很接近 0。请设计一个算法返回每对文档的 ID 及其相似度。只需输出相似度大于 0 的组合。请忽略空文档。为简单起见,可以假定每个文档由一个含有不同整数的数组表示。
@@ -32,14 +33,14 @@The similarity of two documents (each with distinct words) is defined to be the size of the intersection divided by the size of the union. For example, if the documents consist of integers, the similarity of {1, 5, 3} and {1, 7, 2, 3} is 0.4, because the intersection has size 2 and the union has size 5. We have a long list of documents (with distinct values and each with an associated ID) where the similarity is believed to be "sparse". That is, any two arbitrarily selected documents are very likely to have similarity 0. Design an algorithm that returns a list of pairs of document IDs and the associated similarity.
- +The similarity of two documents (each with distinct words) is defined to be the size of the intersection divided by the size of the union. For example, if the documents consist of integers, the similarity of {1, 5, 3} and {1, 7, 2, 3} is 0.4, because the intersection has size 2 and the union has size 5. We have a long list of documents (with distinct values and each with an associated ID) where the similarity is believed to be "sparse". That is, any two arbitrarily selected documents are very likely to have similarity 0. Design an algorithm that returns a list of pairs of document IDs and the associated similarity.
Input is a 2D array docs
, where docs[i]
is the document with id i
. Return an array of strings, where each string represents a pair of documents with similarity greater than 0. The string should be formatted as {id1},{id2}: {similarity}
, where id1
is the smaller id in the two documents, and similarity
is the similarity rounded to four decimal places. You can return the array in any order.
Example:
- -Input: @@ -43,24 +38,16 @@ ]- -
Note:
- -docs.length <= 500
docs[i].length <= 500
给定一个整数数组 nums
和一个目标值 target
,请你在该数组中找出和为目标值的那 两个 整数,并返回他们的数组下标。
Given an array of integers, return indices of the two numbers such that they add up to a specific target.
- +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, and you may not use the same element twice.
- -Example:
- -Given nums = [2, 7, 11, 15], target = 9, @@ -27,12 +22,8 @@ return [0, 1].- - - ## Solutions - ### **Python3** @@ -48,8 +39,9 @@ return [0, 1]. ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0001.Two Sum/Solution.js b/solution/0000-0099/0001.Two Sum/Solution.js index b0bd22cd58491..65dce780ea093 100644 --- a/solution/0000-0099/0001.Two Sum/Solution.js +++ b/solution/0000-0099/0001.Two Sum/Solution.js @@ -2,22 +2,22 @@ * Author: limbowandering */ -const twoSum = function(nums, target) { +const twoSum = function (nums, target) { const map = {}; for (let i = 0; i < nums.length; i++) { if (map[nums[i]] !== undefined) { - return [map[nums[i]], i] + return [map[nums[i]], i]; } else { - map[target - nums[i]] = i + map[target - nums[i]] = i; } - } + } }; -/** +/** * Author: Mcnwork2018 */ -var twoSum = function(nums, target) { +var twoSum = function (nums, target) { let len = nums.length; let n = {}; for (let i = 0; i < len; i++) { @@ -32,12 +32,12 @@ var twoSum = function(nums, target) { * Author: rookie */ -var twoSum = function(nums, target) { +var twoSum = function (nums, target) { const map = new Map(); for (let i = 0; i < nums.length; i++) { if (map.has(target - nums[i])) { - return [ map.get(target - nums[i]), i ] + return [map.get(target - nums[i]), i]; } map.set(nums[i], i); } -}; \ No newline at end of file +}; diff --git a/solution/0000-0099/0002.Add Two Numbers/README.md b/solution/0000-0099/0002.Add Two Numbers/README.md index 70f6c30985c53..b4bed47b9e5da 100644 --- a/solution/0000-0099/0002.Add Two Numbers/README.md +++ b/solution/0000-0099/0002.Add Two Numbers/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0002.Add%20Two%20Numbers/README_EN.md) ## 题目描述 +
给出两个 非空 的链表用来表示两个非负的整数。其中,它们各自的位数是按照 逆序 的方式存储的,并且它们的每个节点只能存储 一位 数字。
@@ -17,15 +18,14 @@ 原因:342 + 465 = 807 - - ## 解法 - + ### **Python3** + ```python @@ -33,6 +33,7 @@ ``` ### **Java** + ```java @@ -40,8 +41,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0002.Add Two Numbers/README_EN.md b/solution/0000-0099/0002.Add Two Numbers/README_EN.md index 09a5852db512b..d960ea5ba7b69 100644 --- a/solution/0000-0099/0002.Add Two Numbers/README_EN.md +++ b/solution/0000-0099/0002.Add Two Numbers/README_EN.md @@ -3,18 +3,13 @@ [中文文档](/solution/0000-0099/0002.Add%20Two%20Numbers/README.md) ## Description -You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a linked list.
- +You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a linked list.
You may assume the two numbers do not contain any leading zero, except the number 0 itself.
- -Example:
- -Input: (2 -> 4 -> 3) + (5 -> 6 -> 4) @@ -25,12 +20,8 @@- - - ## Solutions - ### **Python3** @@ -46,8 +37,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0002.Add Two Numbers/Solution.js b/solution/0000-0099/0002.Add Two Numbers/Solution.js index c9fc0b9898542..e2122af2190c9 100644 --- a/solution/0000-0099/0002.Add Two Numbers/Solution.js +++ b/solution/0000-0099/0002.Add Two Numbers/Solution.js @@ -12,29 +12,34 @@ */ /** - * Author: Mcnwork2018 + * Author: Mcnwork2018 */ var addTwoNumbers = function (l1, l2) { - let c1 = l1, c2 = l2, c3 = 0, l3 = 0, carry = 0; - while (c1 || c2 || carry) { - var v1 = 0, v2 = 0; - if (c1) { - v1 = c1.val; - c1 = c1.next; - } - if (c2) { - v2 = c2.val; - c2 = c2.next; - } - var sum = v1 + v2 + carry; - carry = (sum - sum % 10) / 10; - if (!c3) { - l3 = new ListNode(sum % 10); - c3 = l3; - } else { - c3.next = new ListNode(sum % 10); - c3 = c3.next; - } - } - return l3; -} \ No newline at end of file + let c1 = l1, + c2 = l2, + c3 = 0, + l3 = 0, + carry = 0; + while (c1 || c2 || carry) { + var v1 = 0, + v2 = 0; + if (c1) { + v1 = c1.val; + c1 = c1.next; + } + if (c2) { + v2 = c2.val; + c2 = c2.next; + } + var sum = v1 + v2 + carry; + carry = (sum - (sum % 10)) / 10; + if (!c3) { + l3 = new ListNode(sum % 10); + c3 = l3; + } else { + c3.next = new ListNode(sum % 10); + c3 = c3.next; + } + } + return l3; +}; diff --git a/solution/0000-0099/0003.Longest Substring Without Repeating Characters/README.md b/solution/0000-0099/0003.Longest Substring Without Repeating Characters/README.md index 7027001bc5d8f..e16c92e411535 100644 --- a/solution/0000-0099/0003.Longest Substring Without Repeating Characters/README.md +++ b/solution/0000-0099/0003.Longest Substring Without Repeating Characters/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0003.Longest%20Substring%20Without%20Repeating%20Characters/README_EN.md) ## 题目描述 +
给定一个字符串,请你找出其中不含有重复字符的 最长子串 的长度。
@@ -28,15 +29,14 @@ 请注意,你的答案必须是 子串 的长度,"pwke"
是一个子序列,不是子串。
-
-
## 解法
-
+
### **Python3**
+
```python
@@ -44,6 +44,7 @@
```
### **Java**
+
```java
@@ -51,8 +52,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0003.Longest Substring Without Repeating Characters/README_EN.md b/solution/0000-0099/0003.Longest Substring Without Repeating Characters/README_EN.md
index 0ceea987a2322..6ef858c2964dc 100644
--- a/solution/0000-0099/0003.Longest Substring Without Repeating Characters/README_EN.md
+++ b/solution/0000-0099/0003.Longest Substring Without Repeating Characters/README_EN.md
@@ -3,16 +3,13 @@
[中文文档](/solution/0000-0099/0003.Longest%20Substring%20Without%20Repeating%20Characters/README.md)
## Description
-Given a string, find the length of the longest substring without repeating characters.
- +Given a string, find the length of the longest substring without repeating characters.
Example 1:
- -
Input: "abcabcbb"
@@ -23,14 +20,10 @@
-
-
Example 2:
- -
Input: "bbbbb"
@@ -41,14 +34,10 @@
-
-
Example 3:
- -
Input: "pwwkew"
@@ -67,12 +56,8 @@
给定两个大小为 m 和 n 的有序数组 nums1
和 nums2
。
There are two sorted arrays nums1 and nums2 of size m and n respectively.
- +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 should be O(log (m+n)).
- -You may assume nums1 and nums2 cannot be both empty.
- -Example 1:
- -nums1 = [1, 3] @@ -31,12 +24,8 @@ The median is 2.0- -
Example 2:
- -nums1 = [1, 2] @@ -49,12 +38,8 @@ The median is (2 + 3)/2 = 2.5- - - ## Solutions - ### **Python3** @@ -70,8 +55,9 @@ The median is (2 + 3)/2 = 2.5 ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0004.Median of Two Sorted Arrays/Solution.js b/solution/0000-0099/0004.Median of Two Sorted Arrays/Solution.js index 82afa8c8fa27e..929b6e5dbe7c1 100644 --- a/solution/0000-0099/0004.Median of Two Sorted Arrays/Solution.js +++ b/solution/0000-0099/0004.Median of Two Sorted Arrays/Solution.js @@ -4,64 +4,67 @@ * @return {number} 012345 */ var findMedianSortedArrays = function (nums1, nums2) { - if (nums1.length == 0 || nums2.length == 0) { - if ((nums1.length + nums2.length) % 2 == 1) { - const index = parseInt((nums1.length + nums2.length) / 2) - return nums2.length == 0 ? nums1[index] : nums2[index] - } else { - let nums = nums2.length == 0 ? nums1 : nums2 - const index = nums.length / 2 - return (nums[index - 1] + nums[index]) / 2 - } + if (nums1.length == 0 || nums2.length == 0) { + if ((nums1.length + nums2.length) % 2 == 1) { + const index = parseInt((nums1.length + nums2.length) / 2); + return nums2.length == 0 ? nums1[index] : nums2[index]; + } else { + let nums = nums2.length == 0 ? nums1 : nums2; + const index = nums.length / 2; + return (nums[index - 1] + nums[index]) / 2; } + } - if (nums1.length > nums2.length) { - swap(nums1, nums2) + if (nums1.length > nums2.length) { + swap(nums1, nums2); + } + const M = nums1.length, + N = nums2.length; + let min = 0, + max = M, + half = parseInt((M + N + 1) / 2); // 连个数组合并的中间值 + while (min <= max) { + let i = parseInt((min + max) / 2); // nums1 的索引值 + let j = half - i; // num2 的索引值 + if (i < max && nums2[j - 1] > nums1[i]) { + min++; + } else if (i > min && nums1[i - 1] > nums2[j]) { + max--; + } else { + let maxLeft = 0; + if (i == 0) { + maxLeft = nums2[j - 1]; + } else if (j == 0) { + maxLeft = nums1[i - 1]; + } else { + maxLeft = Math.max(nums1[i - 1], nums2[j - 1]); + } + if ((M + N) % 2 == 1) { + return maxLeft; + } + let minRight = 0; + if (i == M) { + minRight = nums2[j]; + } else if (j == N) { + minRight = nums1[i]; + } else { + minRight = Math.min(nums1[i], nums2[j]); + } + return (maxLeft + minRight) / 2; } - const M = nums1.length, N = nums2.length - let min = 0, max = M, half = parseInt((M + N + 1) / 2) // 连个数组合并的中间值 - while (min <= max) { - let i = parseInt((min + max) / 2) // nums1 的索引值 - let j = half - i // num2 的索引值 - if (i < max && nums2[j - 1] > nums1[i]) { - min++ - } else if (i > min && nums1[i - 1] > nums2[j]) { - max-- - } else { - let maxLeft = 0 - if (i == 0) { - maxLeft = nums2[j - 1] - } else if (j == 0) { - maxLeft = nums1[i - 1] - } else { - maxLeft = Math.max(nums1[i - 1], nums2[j - 1]) - } - if ((M + N) % 2 == 1) { - return maxLeft - } - let minRight = 0 - if (i == M) { - minRight = nums2[j] - } else if (j == N) { - minRight = nums1[i] - } else { - minRight = Math.min(nums1[i], nums2[j]) - } - return (maxLeft + minRight) / 2 - } - } - return 0 + } + return 0; }; function swap(a, b) { - let tmp = a - a = b - b = tmp + let tmp = a; + a = b; + b = tmp; } -const nums1 = [4, 5] -const nums2 = [1, 2, 3] -findMedianSortedArrays(nums1, nums2) +const nums1 = [4, 5]; +const nums2 = [1, 2, 3]; +findMedianSortedArrays(nums1, nums2); /** * 实现思路 @@ -71,4 +74,4 @@ findMedianSortedArrays(nums1, nums2) * 取大数组的索引 = 总中间值-小数组中间值 * 循环直到符合条件 * 如果都不符合条件,那么说明中间值在两个数组的左边或者右边 - */ \ No newline at end of file + */ diff --git a/solution/0000-0099/0005.Longest Palindromic Substring/README.md b/solution/0000-0099/0005.Longest Palindromic Substring/README.md index 2494e18204624..033dfe0def4cb 100644 --- a/solution/0000-0099/0005.Longest Palindromic Substring/README.md +++ b/solution/0000-0099/0005.Longest Palindromic Substring/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0005.Longest%20Palindromic%20Substring/README_EN.md) ## 题目描述 +
给定一个字符串 s
,找到 s
中最长的回文子串。你可以假设 s
的最大长度为 1000。
Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000.
- +Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000.
Example 1:
- -Input: "babad" @@ -21,12 +18,8 @@- -
Example 2:
- -Input: "cbbd" @@ -35,12 +28,8 @@- - - ## Solutions - ### **Python3** @@ -56,8 +45,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0005.Longest Palindromic Substring/Solution.js b/solution/0000-0099/0005.Longest Palindromic Substring/Solution.js index 3371f06d57ebf..9a77a2833d1a0 100644 --- a/solution/0000-0099/0005.Longest Palindromic Substring/Solution.js +++ b/solution/0000-0099/0005.Longest Palindromic Substring/Solution.js @@ -3,34 +3,36 @@ * @return {string} */ var longestPalindrome = function (s) { - let maxLength = 0, left = 0, right = 0 - for (let i = 0; i < s.length; i++) { - let singleCharLength = getPalLenByCenterChar(s, i, i) - let doubleCharLength = getPalLenByCenterChar(s, i, i + 1) - let max = Math.max(singleCharLength, doubleCharLength) - if (max > maxLength) { - maxLength = max - left = i - parseInt((max - 1) / 2) - right = i + parseInt(max / 2) - } + let maxLength = 0, + left = 0, + right = 0; + for (let i = 0; i < s.length; i++) { + let singleCharLength = getPalLenByCenterChar(s, i, i); + let doubleCharLength = getPalLenByCenterChar(s, i, i + 1); + let max = Math.max(singleCharLength, doubleCharLength); + if (max > maxLength) { + maxLength = max; + left = i - parseInt((max - 1) / 2); + right = i + parseInt(max / 2); } - return s.slice(left, right + 1) + } + return s.slice(left, right + 1); }; function getPalLenByCenterChar(s, left, right) { - // 中间值为两个字符,确保两个字符相等 - if (s[left] != s[right]){ - return right - left // 不相等返回为1个字符串 + // 中间值为两个字符,确保两个字符相等 + if (s[left] != s[right]) { + return right - left; // 不相等返回为1个字符串 + } + while (left > 0 && right < s.length - 1) { + // 先加减再判断 + left--; + right++; + if (s[left] != s[right]) { + return right - left - 1; } - while (left > 0 && right < s.length - 1) { - // 先加减再判断 - left-- - right++ - if (s[left] != s[right]){ - return right - left - 1 - } - } - return right - left + 1 + } + return right - left + 1; } -console.log(longestPalindrome("cbbd")) \ No newline at end of file +console.log(longestPalindrome("cbbd")); diff --git a/solution/0000-0099/0006.ZigZag Conversion/README.md b/solution/0000-0099/0006.ZigZag Conversion/README.md index 245ce933c43a9..1e27e07aee5c3 100644 --- a/solution/0000-0099/0006.ZigZag Conversion/README.md +++ b/solution/0000-0099/0006.ZigZag Conversion/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0006.ZigZag%20Conversion/README_EN.md) ## 题目描述 +
将一个给定字符串根据给定的行数,以从上往下、从左到右进行 Z 字形排列。
@@ -36,15 +37,14 @@ E O E I I E C I H N T S G - - ## 解法 - + ### **Python3** + ```python @@ -52,6 +52,7 @@ T S G ``` ### **Java** + ```java @@ -59,8 +60,9 @@ T S G ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0006.ZigZag Conversion/README_EN.md b/solution/0000-0099/0006.ZigZag Conversion/README_EN.md index f32fb59e184d9..3a10fcad6038d 100644 --- a/solution/0000-0099/0006.ZigZag Conversion/README_EN.md +++ b/solution/0000-0099/0006.ZigZag Conversion/README_EN.md @@ -3,9 +3,8 @@ [中文文档](/solution/0000-0099/0006.ZigZag%20Conversion/README.md) ## Description -The string "PAYPALISHIRING"
is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)
The string "PAYPALISHIRING"
is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)
@@ -17,26 +16,16 @@ Y I R- -
And then read line by line: "PAHNAPLSIIGYIR"
Write the code that will take a string and make this conversion given a number of rows:
- -string convert(string s, int numRows);- -
Example 1:
- -Input: s = "PAYPALISHIRING", numRows = 3 @@ -45,12 +34,8 @@ string convert(string s, int numRows);- -
Example 2:
- -Input: s = "PAYPALISHIRING", numRows = 4 @@ -69,12 +54,8 @@ Y A H R P I- - - ## Solutions - ### **Python3** @@ -90,8 +71,9 @@ P I ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0006.ZigZag Conversion/Solution.js b/solution/0000-0099/0006.ZigZag Conversion/Solution.js index 68ea0f89c2a72..62f9913c534f0 100644 --- a/solution/0000-0099/0006.ZigZag Conversion/Solution.js +++ b/solution/0000-0099/0006.ZigZag Conversion/Solution.js @@ -4,29 +4,31 @@ * @return {string} */ var convert = function (s, numRows) { - if (numRows == 1) return s - let arr = new Array(numRows) - for (let i = 0; i < numRows; i++) arr[i] = [] - let index = 0, len = s.length, mi = 0, isDown = true - while (index < len) { - arr[mi].push(s[index]) - index++ + if (numRows == 1) return s; + let arr = new Array(numRows); + for (let i = 0; i < numRows; i++) arr[i] = []; + let index = 0, + len = s.length, + mi = 0, + isDown = true; + while (index < len) { + arr[mi].push(s[index]); + index++; - if (mi >= numRows - 1) - isDown = false - else if (mi <= 0) - isDown = true + if (mi >= numRows - 1) isDown = false; + else if (mi <= 0) isDown = true; - if (isDown) mi++ - else mi-- - } - let ans = [] - for (let item of arr) { - ans = ans.concat(item) - } - return ans.join("") + if (isDown) mi++; + else mi--; + } + let ans = []; + for (let item of arr) { + ans = ans.concat(item); + } + return ans.join(""); }; -const s = "AB", numRows = 1 +const s = "AB", + numRows = 1; -console.log(convert(s, numRows)) \ No newline at end of file +console.log(convert(s, numRows)); diff --git a/solution/0000-0099/0007.Reverse Integer/README.md b/solution/0000-0099/0007.Reverse Integer/README.md index 06091abaf2e54..e585e3b42039c 100644 --- a/solution/0000-0099/0007.Reverse Integer/README.md +++ b/solution/0000-0099/0007.Reverse Integer/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0007.Reverse%20Integer/README_EN.md) ## 题目描述 +
给出一个 32 位的有符号整数,你需要将这个整数中每位上的数字进行反转。
@@ -28,15 +29,14 @@假设我们的环境只能存储得下 32 位的有符号整数,则其数值范围为 [−231, 231 − 1]。请根据这个假设,如果反转后整数溢出那么就返回 0。
- - ## 解法 - + ### **Python3** + ```python @@ -44,6 +44,7 @@ ``` ### **Java** + ```java @@ -51,8 +52,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0007.Reverse Integer/README_EN.md b/solution/0000-0099/0007.Reverse Integer/README_EN.md index da7bfd8b4cf44..77cefc2b6a03a 100644 --- a/solution/0000-0099/0007.Reverse Integer/README_EN.md +++ b/solution/0000-0099/0007.Reverse Integer/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/solution/0000-0099/0007.Reverse%20Integer/README.md) ## Description -Given a 32-bit signed integer, reverse digits of an integer.
- +Given a 32-bit signed integer, reverse digits of an integer.
Example 1:
- -Input: 123 @@ -19,12 +16,8 @@- -
Example 2:
- -Input: -123 @@ -33,12 +26,8 @@- -
Example 3:
- -Input: 120 @@ -47,18 +36,12 @@- -
Note:
Assume we are dealing with an environment which could only store integers within the 32-bit signed integer range: [−231, 231 − 1]. For the purpose of this problem, assume that your function returns 0 when the reversed integer overflows.
请你来实现一个 atoi
函数,使其能将字符串转换成整数。
Implement atoi
which converts a string to an integer.
Implement atoi
which converts a string to an integer.
The function first discards as many whitespace characters as necessary until the first non-whitespace character is found. Then, starting from this character, takes an optional initial plus or minus sign followed by as many numerical digits as possible, and interprets them as a numerical value.
- -The string can contain additional characters after those that form the integral number, which are ignored and have no effect on the behavior of this function.
- -If the first sequence of non-whitespace characters in str is not a valid integral number, or if no such sequence exists because either str is empty or it contains only whitespace characters, no conversion is performed.
- -If no valid conversion could be performed, a zero value is returned.
- -Note:
- -' '
is considered as whitespace character.' '
is considered as whitespace character.Example 1:
- -Input: "42" @@ -49,12 +34,8 @@- -
Example 2:
- -Input: " -42" @@ -67,12 +48,8 @@- -
Example 3:
- -Input: "4193 with words" @@ -83,12 +60,8 @@- -
Example 4:
- -Input: "words and 987" @@ -99,12 +72,8 @@ digit or a +/- sign. Therefore no valid conversion could be performed.- -
Example 5:
- -Input: "-91283472332" @@ -115,12 +84,8 @@ Thefore INT_MIN (−231) is returned.- - - ## Solutions - ### **Python3** @@ -136,8 +101,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0008.String to Integer (atoi)/Solution.js b/solution/0000-0099/0008.String to Integer (atoi)/Solution.js index 9878df64efea7..e73b6cd728ee1 100644 --- a/solution/0000-0099/0008.String to Integer (atoi)/Solution.js +++ b/solution/0000-0099/0008.String to Integer (atoi)/Solution.js @@ -1,23 +1,24 @@ -const myAtoi = function(str){ +const myAtoi = function (str) { str = str.trim(); - if(!str) return 0; + if (!str) return 0; let isPositive = 1; - let i = 0, ans = 0; - if(str[i] === '+'){ + let i = 0, + ans = 0; + if (str[i] === "+") { isPositive = 1; i++; - }else if(str[i] === '-'){ + } else if (str[i] === "-") { isPositive = 0; i++; } - for(; i < str.length; i++){ + for (; i < str.length; i++) { let t = str.charCodeAt(i) - 48; - if(t > 9 || t < 0) break; - if(ans > 2147483647/10 || ans > (2147483647-t)/10){ + if (t > 9 || t < 0) break; + if (ans > 2147483647 / 10 || ans > (2147483647 - t) / 10) { return isPositive ? 2147483647 : -2147483648; - }else{ - ans = ans*10 + t; + } else { + ans = ans * 10 + t; } } - return isPositive? ans : -ans; -} + return isPositive ? ans : -ans; +}; diff --git a/solution/0000-0099/0009.Palindrome Number/README.md b/solution/0000-0099/0009.Palindrome Number/README.md index dd05c3bf9ae9e..18718a5865682 100644 --- a/solution/0000-0099/0009.Palindrome Number/README.md +++ b/solution/0000-0099/0009.Palindrome Number/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0009.Palindrome%20Number/README_EN.md) ## 题目描述 +
判断一个整数是否是回文数。回文数是指正序(从左向右)和倒序(从右向左)读都是一样的整数。
@@ -30,15 +31,14 @@你能不将整数转为字符串来解决这个问题吗?
- - ## 解法 - + ### **Python3** + ```python @@ -46,6 +46,7 @@ ``` ### **Java** + ```java @@ -53,8 +54,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0009.Palindrome Number/README_EN.md b/solution/0000-0099/0009.Palindrome Number/README_EN.md index 3df96110092cb..040213519aa04 100644 --- a/solution/0000-0099/0009.Palindrome Number/README_EN.md +++ b/solution/0000-0099/0009.Palindrome Number/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/solution/0000-0099/0009.Palindrome%20Number/README.md) ## Description -Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward.
- +Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward.
Example 1:
- -Input: 121 @@ -19,12 +16,8 @@- -
Example 2:
- -Input: -121 @@ -35,12 +28,8 @@- -
Example 3:
- -Input: 10 @@ -51,20 +40,12 @@- -
Follow up:
- -Coud you solve it without converting the integer to a string?
- - - ## Solutions - ### **Python3** @@ -80,8 +61,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0009.Palindrome Number/Solution.js b/solution/0000-0099/0009.Palindrome Number/Solution.js index 9876d699cc70d..355cce7972fe3 100644 --- a/solution/0000-0099/0009.Palindrome Number/Solution.js +++ b/solution/0000-0099/0009.Palindrome Number/Solution.js @@ -2,13 +2,14 @@ * @param {number} x * @return {boolean} */ -var isPalindrome = function(x) { - let str = x + "" - let left = 0,right = str.length - 1 - while(left < right){ - if (str[left] != str[right]) return false - left++ - right-- - } - return true -}; \ No newline at end of file +var isPalindrome = function (x) { + let str = x + ""; + let left = 0, + right = str.length - 1; + while (left < right) { + if (str[left] != str[right]) return false; + left++; + right--; + } + return true; +}; diff --git a/solution/0000-0099/0010.Regular Expression Matching/README.md b/solution/0000-0099/0010.Regular Expression Matching/README.md index 66bb2efc1fe86..e4db4a3991ff2 100644 --- a/solution/0000-0099/0010.Regular Expression Matching/README.md +++ b/solution/0000-0099/0010.Regular Expression Matching/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0010.Regular%20Expression%20Matching/README_EN.md) ## 题目描述 +给你一个字符串 s
和一个字符规律 p
,请你来实现一个支持 '.'
和 '*'
的正则表达式匹配。
Given an input string (s
) and a pattern (p
), implement regular expression matching with support for '.'
and '*'
.
@@ -68,11 +69,8 @@ p = "mis*is*p*." Output: false- - ## Solutions - ### **Python3** @@ -88,8 +86,9 @@ p = "mis*is*p*." ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0011.Container With Most Water/README.md b/solution/0000-0099/0011.Container With Most Water/README.md index 02ae5d9168cc9..7dc7d0c447516 100644 --- a/solution/0000-0099/0011.Container With Most Water/README.md +++ b/solution/0000-0099/0011.Container With Most Water/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0011.Container%20With%20Most%20Water/README_EN.md) ## 题目描述 +
给你 n 个非负整数 a1,a2,...,an,每个数代表坐标中的一个点 (i, ai) 。在坐标内画 n 条垂直线,垂直线 i 的两个端点分别为 (i, ai) 和 (i, 0)。找出其中的两条线,使得它们与 x 轴共同构成的容器可以容纳最多的水。
@@ -21,15 +22,14 @@输入:[1,8,6,2,5,4,8,3,7] 输出:49- - ## 解法 - + ### **Python3** + ```python @@ -37,6 +37,7 @@ ``` ### **Java** + ```java @@ -44,8 +45,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0011.Container With Most Water/README_EN.md b/solution/0000-0099/0011.Container With Most Water/README_EN.md index 4db660afa34a6..c7fc7a6f6b698 100644 --- a/solution/0000-0099/0011.Container With Most Water/README_EN.md +++ b/solution/0000-0099/0011.Container With Most Water/README_EN.md @@ -3,41 +3,29 @@ [中文文档](/solution/0000-0099/0011.Container%20With%20Most%20Water/README.md) ## Description -
Given n non-negative integers a1, a2, ..., an , where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two lines, which together with x-axis forms a container, such that the container contains the most water.
- +Given n non-negative integers a1, a2, ..., an , where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two lines, which together with x-axis forms a container, such that the container contains the most water.
Note: You may not slant the container and n is at least 2.
- - -
The above vertical lines are represented by array [1,8,6,2,5,4,8,3,7]. In this case, the max area of water (blue section) the container can contain is 49.
- -- -
Example:
- -Input: [1,8,6,2,5,4,8,3,7] Output: 49- ## Solutions - ### **Python3** @@ -53,8 +41,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0011.Container With Most Water/Solution.js b/solution/0000-0099/0011.Container With Most Water/Solution.js index 5fe55494d506d..3728062a6223f 100644 --- a/solution/0000-0099/0011.Container With Most Water/Solution.js +++ b/solution/0000-0099/0011.Container With Most Water/Solution.js @@ -1,18 +1,20 @@ -const maxArea2 = function(height){ +const maxArea2 = function (height) { let result = 0; - for(let i = 0; i < height.length; i++){ - for(let j = i + 1; j < height.length; j++){ - result = Math.max(result, Math.min(height[i],height[j])*(j-i)); + for (let i = 0; i < height.length; i++) { + for (let j = i + 1; j < height.length; j++) { + result = Math.max(result, Math.min(height[i], height[j]) * (j - i)); } } return result; }; -const maxArea = function(height){ - let result = 0, l = 0, r = height.length - 1; - while(l < r){ - result = Math.max(result, Math.min(height[l],height[r])*(r-l)); +const maxArea = function (height) { + let result = 0, + l = 0, + r = height.length - 1; + while (l < r) { + result = Math.max(result, Math.min(height[l], height[r]) * (r - l)); height[l] < height[r] ? l++ : r--; } return result; -} +}; diff --git a/solution/0000-0099/0012.Integer to Roman/README.md b/solution/0000-0099/0012.Integer to Roman/README.md index a213e903e950c..9a224432548f5 100644 --- a/solution/0000-0099/0012.Integer to Roman/README.md +++ b/solution/0000-0099/0012.Integer to Roman/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0012.Integer%20to%20Roman/README_EN.md) ## 题目描述 +
罗马数字包含以下七种字符: I
, V
, X
, L
,C
,D
和 M
。
Roman numerals are represented by seven different symbols: I
, V
, X
, L
, C
, D
and M
.
Roman numerals are represented by seven different symbols: I
, V
, X
, L
, C
, D
and M
.
@@ -25,72 +24,48 @@ D 500 M 1000- -
For example, two is written as II
in Roman numeral, just two one's added together. Twelve is written as, XII
, which is simply X
+ II
. The number twenty seven is written as XXVII
, which is XX
+ V
+ II
.
Roman numerals are usually written largest to smallest from left to right. However, the numeral for four is not IIII
. Instead, the number four is written as IV
. Because the one is before the five we subtract it making four. The same principle applies to the number nine, which is written as IX
. There are six instances where subtraction is used:
I
can be placed before V
(5) and X
(10) to make 4 and 9. I
can be placed before V
(5) and X
(10) to make 4 and 9. X
can be placed before L
(50) and C
(100) to make 40 and 90. X
can be placed before L
(50) and C
(100) to make 40 and 90. C
can be placed before D
(500) and M
(1000) to make 400 and 900.C
can be placed before D
(500) and M
(1000) to make 400 and 900.Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 to 3999.
- -Example 1:
- -Input: 3 Output: "III"- -
Example 2:
- -Input: 4 Output: "IV"- -
Example 3:
- -Input: 9 Output: "IX"- -
Example 4:
- -Input: 58 @@ -101,12 +76,8 @@ M 1000- -
Example 5:
- -Input: 1994 @@ -115,12 +86,8 @@ M 1000Explanation: M = 1000, CM = 900, XC = 90 and IV = 4. - - - ## Solutions - ### **Python3** @@ -136,8 +103,9 @@ M 1000 ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0013.Roman to Integer/README.md b/solution/0000-0099/0013.Roman to Integer/README.md index d396d85b0298a..fa8caf35e74ff 100644 --- a/solution/0000-0099/0013.Roman to Integer/README.md +++ b/solution/0000-0099/0013.Roman to Integer/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0013.Roman%20to%20Integer/README_EN.md) ## 题目描述 +
罗马数字包含以下七种字符: I
, V
, X
, L
,C
,D
和 M
。
Roman numerals are represented by seven different symbols: I
, V
, X
, L
, C
, D
and M
.
Roman numerals are represented by seven different symbols: I
, V
, X
, L
, C
, D
and M
.
@@ -25,72 +24,48 @@ D 500 M 1000- -
For example, two is written as II
in Roman numeral, just two one's added together. Twelve is written as, XII
, which is simply X
+ II
. The number twenty seven is written as XXVII
, which is XX
+ V
+ II
.
Roman numerals are usually written largest to smallest from left to right. However, the numeral for four is not IIII
. Instead, the number four is written as IV
. Because the one is before the five we subtract it making four. The same principle applies to the number nine, which is written as IX
. There are six instances where subtraction is used:
I
can be placed before V
(5) and X
(10) to make 4 and 9. I
can be placed before V
(5) and X
(10) to make 4 and 9. X
can be placed before L
(50) and C
(100) to make 40 and 90. X
can be placed before L
(50) and C
(100) to make 40 and 90. C
can be placed before D
(500) and M
(1000) to make 400 and 900.C
can be placed before D
(500) and M
(1000) to make 400 and 900.Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 to 3999.
- -Example 1:
- -Input: "III" Output: 3- -
Example 2:
- -Input: "IV" Output: 4- -
Example 3:
- -Input: "IX" Output: 9- -
Example 4:
- -Input: "LVIII" @@ -101,12 +76,8 @@ M 1000- -
Example 5:
- -Input: "MCMXCIV" @@ -115,12 +86,8 @@ M 1000Explanation: M = 1000, CM = 900, XC = 90 and IV = 4. - - - ## Solutions - ### **Python3** @@ -136,8 +103,9 @@ M 1000 ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0013.Roman to Integer/Solution.js b/solution/0000-0099/0013.Roman to Integer/Solution.js index 4ef4037aefe6c..570564b764a8e 100644 --- a/solution/0000-0099/0013.Roman to Integer/Solution.js +++ b/solution/0000-0099/0013.Roman to Integer/Solution.js @@ -1,19 +1,19 @@ -const romanToInt = function(s){ +const romanToInt = function (s) { const map = { - 'I' : 1, - 'V' : 5, - 'X' : 10, - 'L' : 50, - 'C' : 100, - 'D' : 500, - 'M' : 1000 + I: 1, + V: 5, + X: 10, + L: 50, + C: 100, + D: 500, + M: 1000, }; let sum = 0; - for(let i = 0; i < s.length;i++){ - if(map[s[i]] < map[s[i+1]]){ - sum-=map[s[i]]; - }else{ - sum+=map[s[i]]; + for (let i = 0; i < s.length; i++) { + if (map[s[i]] < map[s[i + 1]]) { + sum -= map[s[i]]; + } else { + sum += map[s[i]]; } } return sum; diff --git a/solution/0000-0099/0014.Longest Common Prefix/README.md b/solution/0000-0099/0014.Longest Common Prefix/README.md index d48f4c5931e71..81fd1fd12ceb4 100644 --- a/solution/0000-0099/0014.Longest Common Prefix/README.md +++ b/solution/0000-0099/0014.Longest Common Prefix/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0014.Longest%20Common%20Prefix/README_EN.md) ## 题目描述 +
编写一个函数来查找字符串数组中的最长公共前缀。
@@ -25,15 +26,14 @@所有输入只包含小写字母 a-z
。
Write a function to find the longest common prefix string amongst an array of strings.
- +Write a function to find the longest common prefix string amongst an array of strings.
If there is no common prefix, return an empty string ""
.
Example 1:
- -Input: ["flower","flow","flight"] @@ -23,12 +18,8 @@- -
Example 2:
- -Input: ["dog","racecar","car"] @@ -39,20 +30,12 @@- -
Note:
- -All given inputs are in lowercase letters a-z
.
给你一个包含 n 个整数的数组 nums
,判断 nums
中是否存在三个元素 a,b,c ,使得 a + b + c = 0 ?请你找出所有满足条件且不重复的三元组。
Given an array nums
of n integers, are there elements a, b, c in nums
such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.
Given an array nums
of n integers, are there elements a, b, c in nums
such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.
Note:
- -The solution set must not contain duplicate triplets.
- -Example:
- -Given array nums = [-1, 0, 1, 2, -1, -4], @@ -37,10 +30,8 @@ A solution set is:- ## Solutions - ### **Python3** @@ -56,8 +47,9 @@ A solution set is: ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0016.3Sum Closest/README.md b/solution/0000-0099/0016.3Sum Closest/README.md index ae636f948a890..3a659676428c1 100644 --- a/solution/0000-0099/0016.3Sum Closest/README.md +++ b/solution/0000-0099/0016.3Sum Closest/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0016.3Sum%20Closest/README_EN.md) ## 题目描述 +
给定一个包括 n 个整数的数组 nums
和 一个目标值 target
。找出 nums
中的三个整数,使得它们的和与 target
最接近。返回这三个数的和。假定每组输入只存在唯一答案。
Given an array nums
of n integers and an integer target
, find three integers in nums
such that the sum is closest to target
. Return the sum of the three integers. You may assume that each input would have exactly one solution.
Given an array nums
of n integers and an integer target
, find three integers in nums
such that the sum is closest to target
. Return the sum of the three integers. You may assume that each input would have exactly one solution.
Example:
- -Given array nums = [-1, 2, 1, -4], and target = 1. @@ -21,12 +18,8 @@ The sum that is closest to the target is 2. (-1 + 2 + 1 = 2).- - - ## Solutions - ### **Python3** @@ -42,8 +35,9 @@ The sum that is closest to the target is 2. (-1 + 2 + 1 = 2). ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0017.Letter Combinations of a Phone Number/README.md b/solution/0000-0099/0017.Letter Combinations of a Phone Number/README.md index 966e9c5b0ef9f..0634cfc3756fe 100644 --- a/solution/0000-0099/0017.Letter Combinations of a Phone Number/README.md +++ b/solution/0000-0099/0017.Letter Combinations of a Phone Number/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0017.Letter%20Combinations%20of%20a%20Phone%20Number/README_EN.md) ## 题目描述 +
给定一个仅包含数字 2-9
的字符串,返回所有它能表示的字母组合。
说明:
尽管上面的答案是按字典序排列的,但是你可以任意选择答案输出的顺序。
Given a string containing digits from 2-9
inclusive, return all possible letter combinations that the number could represent.
Given a string containing digits from 2-9
inclusive, return all possible letter combinations that the number could represent.
A mapping of digit to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any letters.
 -Example:
- -Input: "23" @@ -24,20 +20,12 @@- -
Note:
- -Although the above answer is in lexicographical order, your answer could be in any order you want.
- - - ## Solutions - ### **Python3** @@ -53,8 +41,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0018.4Sum/README.md b/solution/0000-0099/0018.4Sum/README.md index c399d858c1d33..7de062388b543 100644 --- a/solution/0000-0099/0018.4Sum/README.md +++ b/solution/0000-0099/0018.4Sum/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0018.4Sum/README_EN.md) ## 题目描述 +给定一个包含 n 个整数的数组 nums
和一个目标值 target
,判断 nums
中是否存在四个元素 a,b,c 和 d ,使得 a + b + c + d 的值与 target
相等?找出所有满足条件且不重复的四元组。
Given an array nums
of n integers and an integer target
, are there elements a, b, c, and d in nums
such that a + b + c + d = target
? Find all unique quadruplets in the array which gives the sum of target
.
Given an array nums
of n integers and an integer target
, are there elements a, b, c, and d in nums
such that a + b + c + d = target
? Find all unique quadruplets in the array which gives the sum of target
.
Note:
- -The solution set must not contain duplicate quadruplets.
- -Example:
- -Given array nums = [1, 0, -1, 0, -2, 2], and target = 0. @@ -39,12 +32,8 @@ A solution set is:- - - ## Solutions - ### **Python3** @@ -60,8 +49,9 @@ A solution set is: ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0019.Remove Nth Node From End of List/README.md b/solution/0000-0099/0019.Remove Nth Node From End of List/README.md index 137d0793eed70..e439b292ff9f6 100644 --- a/solution/0000-0099/0019.Remove Nth Node From End of List/README.md +++ b/solution/0000-0099/0019.Remove Nth Node From End of List/README.md @@ -1,8 +1,9 @@ -# [19. 删除链表的倒数第N个节点](https://leetcode-cn.com/problems/remove-nth-node-from-end-of-list) +# [19. 删除链表的倒数第 N 个节点](https://leetcode-cn.com/problems/remove-nth-node-from-end-of-list) [English Version](/solution/0000-0099/0019.Remove%20Nth%20Node%20From%20End%20of%20List/README_EN.md) ## 题目描述 +
给定一个链表,删除链表的倒数第 n 个节点,并且返回链表的头结点。
@@ -21,15 +22,14 @@你能尝试使用一趟扫描实现吗?
- - ## 解法 - + ### **Python3** + ```python @@ -37,6 +37,7 @@ ``` ### **Java** + ```java @@ -44,8 +45,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0019.Remove Nth Node From End of List/README_EN.md b/solution/0000-0099/0019.Remove Nth Node From End of List/README_EN.md index 3bfa09a67c17f..82bd63a4851ff 100644 --- a/solution/0000-0099/0019.Remove Nth Node From End of List/README_EN.md +++ b/solution/0000-0099/0019.Remove Nth Node From End of List/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/solution/0000-0099/0019.Remove%20Nth%20Node%20From%20End%20of%20List/README.md) ## Description -Given a linked list, remove the n-th node from the end of list and return its head.
- +Given a linked list, remove the n-th node from the end of list and return its head.
Example:
- -Given linked list: 1->2->3->4->5, and n = 2. @@ -21,28 +18,16 @@ After removing the second node from the end, the linked list becomes 1-&- -
Note:
- -Given n will always be valid.
- -Follow up:
- -Could you do this in one pass?
- - - ## Solutions - ### **Python3** @@ -58,8 +43,9 @@ After removing the second node from the end, the linked list becomes 1-& ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0019.Remove Nth Node From End of List/Solution.js b/solution/0000-0099/0019.Remove Nth Node From End of List/Solution.js index ab98a2c7e26f0..cca2368bc21f7 100644 --- a/solution/0000-0099/0019.Remove Nth Node From End of List/Solution.js +++ b/solution/0000-0099/0019.Remove Nth Node From End of List/Solution.js @@ -1,13 +1,15 @@ -const removeNthFromEnd = function(head, n){ - let left, before, right = head; - left = before = {next: head}; - while(n--){ - right = right.next; +const removeNthFromEnd = function (head, n) { + let left, + before, + right = head; + left = before = { next: head }; + while (n--) { + right = right.next; } - while(right){ - right =right.next; - left = left.next; + while (right) { + right = right.next; + left = left.next; } left.next = left.next.next; return before.next; -} \ No newline at end of file +}; diff --git a/solution/0000-0099/0020.Valid Parentheses/README.md b/solution/0000-0099/0020.Valid Parentheses/README.md index 63ed2d53957df..7e93f38b9493a 100644 --- a/solution/0000-0099/0020.Valid Parentheses/README.md +++ b/solution/0000-0099/0020.Valid Parentheses/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0020.Valid%20Parentheses/README_EN.md) ## 题目描述 +给定一个只包括 '('
,')'
,'{'
,'}'
,'['
,']'
的字符串,判断字符串是否有效。
输入: "{[]}" 输出: true- - ## 解法 - + ### **Python3** + ```python @@ -60,6 +60,7 @@ ``` ### **Java** + ```java @@ -67,8 +68,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0020.Valid Parentheses/README_EN.md b/solution/0000-0099/0020.Valid Parentheses/README_EN.md index dda56fa473a6c..d466b4bbe96fb 100644 --- a/solution/0000-0099/0020.Valid Parentheses/README_EN.md +++ b/solution/0000-0099/0020.Valid Parentheses/README_EN.md @@ -3,32 +3,23 @@ [中文文档](/solution/0000-0099/0020.Valid%20Parentheses/README.md) ## Description -
Given a string containing just the characters '('
, ')'
, '{'
, '}'
, '['
and ']'
, determine if the input string is valid.
Given a string containing just the characters '('
, ')'
, '{'
, '}'
, '['
and ']'
, determine if the input string is valid.
An input string is valid if:
- -Note that an empty string is also considered valid.
- -Example 1:
- -Input: "()" @@ -37,12 +28,8 @@- -
Example 2:
- -Input: "()[]{}" @@ -51,12 +38,8 @@- -
Example 3:
- -Input: "(]" @@ -65,12 +48,8 @@- -
Example 4:
- -Input: "([)]" @@ -79,12 +58,8 @@- -
Example 5:
- -Input: "{[]}" @@ -93,12 +68,8 @@- - - ## Solutions - ### **Python3** @@ -114,8 +85,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0020.Valid Parentheses/Solution.js b/solution/0000-0099/0020.Valid Parentheses/Solution.js index dc59c7cf0600a..1762946b7e25b 100644 --- a/solution/0000-0099/0020.Valid Parentheses/Solution.js +++ b/solution/0000-0099/0020.Valid Parentheses/Solution.js @@ -1,14 +1,14 @@ -const isValid = function(s){ +const isValid = function (s) { let arr = []; - for(let i = 0; i < s.length; i++){ - if(s[i] === '{' || s[i] === '[' || s[i] === '('){ + for (let i = 0; i < s.length; i++) { + if (s[i] === "{" || s[i] === "[" || s[i] === "(") { arr.push(s[i]); - }else{ - if(s[i] === ')' && arr[arr.length-1] === '(') arr.pop(); - else if(s[i] === ']' && arr[arr.length-1] === '[') arr.pop(); - else if(s[i] === '}' && arr[arr.length-1] === '{') arr.pop(); + } else { + if (s[i] === ")" && arr[arr.length - 1] === "(") arr.pop(); + else if (s[i] === "]" && arr[arr.length - 1] === "[") arr.pop(); + else if (s[i] === "}" && arr[arr.length - 1] === "{") arr.pop(); else return false; } } return arr.length === 0; -}; \ No newline at end of file +}; diff --git a/solution/0000-0099/0021.Merge Two Sorted Lists/README.md b/solution/0000-0099/0021.Merge Two Sorted Lists/README.md index 712b78f6d9648..10c56d22b7174 100644 --- a/solution/0000-0099/0021.Merge Two Sorted Lists/README.md +++ b/solution/0000-0099/0021.Merge Two Sorted Lists/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0021.Merge%20Two%20Sorted%20Lists/README_EN.md) ## 题目描述 +
将两个有序链表合并为一个新的有序链表并返回。新链表是通过拼接给定的两个链表的所有节点组成的。
@@ -12,15 +13,14 @@ 输出:1->1->2->3->4->4 - - ## 解法 - + ### **Python3** + ```python @@ -28,6 +28,7 @@ ``` ### **Java** + ```java @@ -35,8 +36,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0021.Merge Two Sorted Lists/README_EN.md b/solution/0000-0099/0021.Merge Two Sorted Lists/README_EN.md index 322145cd8e57e..d422acfa17dc1 100644 --- a/solution/0000-0099/0021.Merge Two Sorted Lists/README_EN.md +++ b/solution/0000-0099/0021.Merge Two Sorted Lists/README_EN.md @@ -3,9 +3,8 @@ [中文文档](/solution/0000-0099/0021.Merge%20Two%20Sorted%20Lists/README.md) ## Description -Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.
- +Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.
Example: @@ -19,10 +18,8 @@
- ## Solutions - ### **Python3** @@ -38,8 +35,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0021.Merge Two Sorted Lists/Solution.js b/solution/0000-0099/0021.Merge Two Sorted Lists/Solution.js index b1ee023fcb56f..83553675d9e20 100644 --- a/solution/0000-0099/0021.Merge Two Sorted Lists/Solution.js +++ b/solution/0000-0099/0021.Merge Two Sorted Lists/Solution.js @@ -9,7 +9,8 @@ const mergeTwoLists2 = function (l1, l2) { return l2; } if (l1 !== null && l2 !== null) { - let t = null, h = null; + let t = null, + h = null; if (l1.val > l2.val) { t = l2; h = l2; @@ -42,7 +43,7 @@ const mergeTwoLists2 = function (l1, l2) { } return h; } -} +}; const mergeTwoLists = function (l1, l2) { if (l1 === null) return l2; @@ -54,4 +55,4 @@ const mergeTwoLists = function (l1, l2) { l2.next = mergeTwoLists(l1, l2.next); return l2; } -} \ No newline at end of file +}; diff --git a/solution/0000-0099/0022.Generate Parentheses/README.md b/solution/0000-0099/0022.Generate Parentheses/README.md index 566acdf11f96d..94c9825c523e9 100644 --- a/solution/0000-0099/0022.Generate Parentheses/README.md +++ b/solution/0000-0099/0022.Generate Parentheses/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0022.Generate%20Parentheses/README_EN.md) ## 题目描述 +给出 n 代表生成括号的对数,请你写出一个函数,使其能够生成所有可能的并且有效的括号组合。
@@ -17,15 +18,14 @@ ] - - ## 解法 - + ### **Python3** + ```python @@ -33,6 +33,7 @@ ``` ### **Java** + ```java @@ -40,8 +41,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0022.Generate Parentheses/README_EN.md b/solution/0000-0099/0022.Generate Parentheses/README_EN.md index 7948ecd7201be..73ca9e10e526e 100644 --- a/solution/0000-0099/0022.Generate Parentheses/README_EN.md +++ b/solution/0000-0099/0022.Generate Parentheses/README_EN.md @@ -3,14 +3,13 @@ [中文文档](/solution/0000-0099/0022.Generate%20Parentheses/README.md) ## Description +Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.
- -For example, given n = 3, a solution set is: @@ -35,10 +34,8 @@ For example, given n = 3, a solution set is: - ## Solutions - ### **Python3** @@ -54,8 +51,9 @@ For example, given n = 3, a solution set is: ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0023.Merge k Sorted Lists/README.md b/solution/0000-0099/0023.Merge k Sorted Lists/README.md index 1094cbb2de152..bc606577a3100 100644 --- a/solution/0000-0099/0023.Merge k Sorted Lists/README.md +++ b/solution/0000-0099/0023.Merge k Sorted Lists/README.md @@ -1,8 +1,9 @@ -# [23. 合并K个排序链表](https://leetcode-cn.com/problems/merge-k-sorted-lists) +# [23. 合并 K 个排序链表](https://leetcode-cn.com/problems/merge-k-sorted-lists) [English Version](/solution/0000-0099/0023.Merge%20k%20Sorted%20Lists/README_EN.md) ## 题目描述 +
合并 k 个排序链表,返回合并后的排序链表。请分析和描述算法的复杂度。
@@ -16,15 +17,14 @@ ] 输出: 1->1->2->3->4->4->5->6 - - ## 解法 - + ### **Python3** + ```python @@ -32,6 +32,7 @@ ``` ### **Java** + ```java @@ -39,8 +40,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0023.Merge k Sorted Lists/README_EN.md b/solution/0000-0099/0023.Merge k Sorted Lists/README_EN.md index 72fb7318c0fd2..4a3fc04bafa72 100644 --- a/solution/0000-0099/0023.Merge k Sorted Lists/README_EN.md +++ b/solution/0000-0099/0023.Merge k Sorted Lists/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/solution/0000-0099/0023.Merge%20k%20Sorted%20Lists/README.md) ## Description -Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.
- +Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.
Example:
- -Input: @@ -29,12 +26,8 @@- - - ## Solutions - ### **Python3** @@ -50,8 +43,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0024.Swap Nodes in Pairs/README.md b/solution/0000-0099/0024.Swap Nodes in Pairs/README.md index 71facf4262a32..09f9daee9e468 100644 --- a/solution/0000-0099/0024.Swap Nodes in Pairs/README.md +++ b/solution/0000-0099/0024.Swap Nodes in Pairs/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0024.Swap%20Nodes%20in%20Pairs/README_EN.md) ## 题目描述 +
给定一个链表,两两交换其中相邻的节点,并返回交换后的链表。
@@ -15,15 +16,14 @@给定- - ## 解法 - + ### **Python3** + ```python @@ -31,6 +31,7 @@ ``` ### **Java** + ```java @@ -38,8 +39,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0024.Swap Nodes in Pairs/README_EN.md b/solution/0000-0099/0024.Swap Nodes in Pairs/README_EN.md index d52d51b2528e9..33a3b8d870d50 100644 --- a/solution/0000-0099/0024.Swap Nodes in Pairs/README_EN.md +++ b/solution/0000-0099/0024.Swap Nodes in Pairs/README_EN.md @@ -3,34 +3,23 @@ [中文文档](/solution/0000-0099/0024.Swap%20Nodes%20in%20Pairs/README.md) ## Description -1->2->3->4
, 你应该返回2->1->4->3
.
Given a linked list, swap every two adjacent nodes and return its head.
- +Given a linked list, swap every two adjacent nodes and return its head.
You may not modify the values in the list's nodes, only nodes itself may be changed.
- -- -
Example:
- -Given- - - ## Solutions - ### **Python3** @@ -46,8 +35,9 @@ Given1->2->3->4
, you should return the list as2->1->4->3
.
1->2->3->4
, you should return the list as 2-&g
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0025.Reverse Nodes in k-Group/README.md b/solution/0000-0099/0025.Reverse Nodes in k-Group/README.md
index ed214a9af07e4..a8022cce23fe2 100644
--- a/solution/0000-0099/0025.Reverse Nodes in k-Group/README.md
+++ b/solution/0000-0099/0025.Reverse Nodes in k-Group/README.md
@@ -3,6 +3,7 @@
[English Version](/solution/0000-0099/0025.Reverse%20Nodes%20in%20k-Group/README_EN.md)
## 题目描述
+
给你一个链表,每 k 个节点一组进行翻转,请你返回翻转后的链表。
@@ -29,15 +30,14 @@
你不能只是单纯的改变节点内部的值,而是需要实际进行节点交换。
-
-
## 解法
-
+
### **Python3**
+
```python
@@ -45,6 +45,7 @@
```
### **Java**
+
```java
@@ -52,8 +53,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0025.Reverse Nodes in k-Group/README_EN.md b/solution/0000-0099/0025.Reverse Nodes in k-Group/README_EN.md
index 90d54bf622fb7..bf45103174702 100644
--- a/solution/0000-0099/0025.Reverse Nodes in k-Group/README_EN.md
+++ b/solution/0000-0099/0025.Reverse Nodes in k-Group/README_EN.md
@@ -3,54 +3,35 @@
[中文文档](/solution/0000-0099/0025.Reverse%20Nodes%20in%20k-Group/README.md)
## Description
-Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.
-
+Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.
k is a positive integer and is less than or equal to the length of the linked list. If the number of nodes is not a multiple of k then left-out nodes in the end should remain as it is.
-
-
-
-
Example:
-
-
Given this linked list: 1->2->3->4->5
-
-
For k = 2, you should return: 2->1->4->3->5
-
-
For k = 3, you should return: 3->2->1->4->5
-
-
Note:
-
-
- - Only constant extra memory is allowed.
+ - Only constant extra memory is allowed.
- - You may not alter the values in the list's nodes, only nodes itself may be changed.
+ - You may not alter the values in the list's nodes, only nodes itself may be changed.
-
-
-
## Solutions
-
### **Python3**
@@ -66,8 +47,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0026.Remove Duplicates from Sorted Array/README.md b/solution/0000-0099/0026.Remove Duplicates from Sorted Array/README.md
index 96052c625e537..dc51dfb669135 100644
--- a/solution/0000-0099/0026.Remove Duplicates from Sorted Array/README.md
+++ b/solution/0000-0099/0026.Remove Duplicates from Sorted Array/README.md
@@ -3,6 +3,7 @@
[English Version](/solution/0000-0099/0026.Remove%20Duplicates%20from%20Sorted%20Array/README_EN.md)
## 题目描述
+
给定一个排序数组,你需要在 原地 删除重复出现的元素,使得每个元素只出现一次,返回移除后数组的新长度。
@@ -47,15 +48,14 @@ for (int i = 0; i < len; i++) {
}
-
-
## 解法
-
+
### **Python3**
+
```python
@@ -63,6 +63,7 @@ for (int i = 0; i < len; i++) {
```
### **Java**
+
```java
@@ -70,8 +71,9 @@ for (int i = 0; i < len; i++) {
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0026.Remove Duplicates from Sorted Array/README_EN.md b/solution/0000-0099/0026.Remove Duplicates from Sorted Array/README_EN.md
index 638e44384f5fd..2d88f4811e087 100644
--- a/solution/0000-0099/0026.Remove Duplicates from Sorted Array/README_EN.md
+++ b/solution/0000-0099/0026.Remove Duplicates from Sorted Array/README_EN.md
@@ -3,18 +3,13 @@
[中文文档](/solution/0000-0099/0026.Remove%20Duplicates%20from%20Sorted%20Array/README.md)
## Description
-Given a sorted array nums, remove the duplicates in-place such that each element appear only once and return the new length.
-
+Given a sorted array nums, remove the duplicates in-place such that each element appear only once and return the new length.
Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory.
-
-
Example 1:
-
-
Given nums = [1,1,2],
@@ -27,12 +22,8 @@ Your function should return length = 2
, with the f
It doesn't matter what you leave beyond the returned length.
-
-
Example 2:
-
-
Given nums = [0,0,1,1,1,2,2,3,3,4],
@@ -47,24 +38,14 @@ It doesn't matter what values are set beyond the returned length.
-
-
Clarification:
-
-
Confused why the returned value is an integer but your answer is an array?
-
-
Note that the input array is passed in by reference, which means modification to the input array will be known to the caller as well.
-
-
Internally you can think of this:
-
-
// nums is passed in by reference. (i.e., without making a copy)
@@ -83,10 +64,8 @@ for (int i = 0; i < len; i++) {
}
-
## Solutions
-
### **Python3**
@@ -102,8 +81,9 @@ for (int i = 0; i < len; i++) {
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0026.Remove Duplicates from Sorted Array/Solution.js b/solution/0000-0099/0026.Remove Duplicates from Sorted Array/Solution.js
index 8b0bac0adc70a..02084311a426c 100644
--- a/solution/0000-0099/0026.Remove Duplicates from Sorted Array/Solution.js
+++ b/solution/0000-0099/0026.Remove Duplicates from Sorted Array/Solution.js
@@ -1,11 +1,11 @@
-const removeDuplicates = function(nums){
+const removeDuplicates = function (nums) {
let i = 1;
let t = 0;
let t2 = nums[0];
let res = 1;
let length = nums.length;
- for(let k = 1; k < length; k++){
- if(nums[k] - nums[k-1] !== 0 && nums[k] !== t2){
+ for (let k = 1; k < length; k++) {
+ if (nums[k] - nums[k - 1] !== 0 && nums[k] !== t2) {
t2 = nums[k];
t = nums[i];
nums[i] = nums[k];
@@ -15,4 +15,4 @@ const removeDuplicates = function(nums){
}
}
return res;
-}
\ No newline at end of file
+};
diff --git a/solution/0000-0099/0027.Remove Element/README.md b/solution/0000-0099/0027.Remove Element/README.md
index e3c044400ac68..c50b5f4509341 100644
--- a/solution/0000-0099/0027.Remove Element/README.md
+++ b/solution/0000-0099/0027.Remove Element/README.md
@@ -3,6 +3,7 @@
[English Version](/solution/0000-0099/0027.Remove%20Element/README_EN.md)
## 题目描述
+
给你一个数组 nums 和一个值 val,你需要 原地 移除所有数值等于 val 的元素,并返回移除后数组的新长度。
@@ -52,15 +53,14 @@ for (int i = 0; i < len; i++) {
}
-
-
## 解法
-
+
### **Python3**
+
```python
@@ -68,6 +68,7 @@ for (int i = 0; i < len; i++) {
```
### **Java**
+
```java
@@ -75,8 +76,9 @@ for (int i = 0; i < len; i++) {
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0027.Remove Element/README_EN.md b/solution/0000-0099/0027.Remove Element/README_EN.md
index 767530f246cd3..1774515cc6b33 100644
--- a/solution/0000-0099/0027.Remove Element/README_EN.md
+++ b/solution/0000-0099/0027.Remove Element/README_EN.md
@@ -3,22 +3,15 @@
[中文文档](/solution/0000-0099/0027.Remove%20Element/README.md)
## Description
-Given an array nums and a value val, remove all instances of that value in-place and return the new length.
-
+Given an array nums and a value val, remove all instances of that value in-place and return the new length.
Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory.
-
-
The order of elements can be changed. It doesn't matter what you leave beyond the new length.
-
-
Example 1:
-
-
Given nums = [3,2,2,3], val = 3,
@@ -33,12 +26,8 @@ It doesn't matter what you leave beyond the returned length.
-
-
Example 2:
-
-
Given nums = [0,1,2,2,3,0,4,2], val = 2,
@@ -55,24 +44,14 @@ Note that the order of those five elements can be arbitrary.
It doesn't matter what values are set beyond the returned length.
-
-
Clarification:
-
-
Confused why the returned value is an integer but your answer is an array?
-
-
Note that the input array is passed in by reference, which means modification to the input array will be known to the caller as well.
-
-
Internally you can think of this:
-
-
// nums is passed in by reference. (i.e., without making a copy)
@@ -91,10 +70,8 @@ for (int i = 0; i < len; i++) {
}
-
## Solutions
-
### **Python3**
@@ -110,8 +87,9 @@ for (int i = 0; i < len; i++) {
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0027.Remove Element/Solution.js b/solution/0000-0099/0027.Remove Element/Solution.js
index b4d8bcc06deca..9a6bc0c76db12 100644
--- a/solution/0000-0099/0027.Remove Element/Solution.js
+++ b/solution/0000-0099/0027.Remove Element/Solution.js
@@ -1,31 +1,31 @@
var removeElement3 = function (nums, val) {
- let len = nums.length
+ let len = nums.length;
if (len < 1) {
- return 0
+ return 0;
}
- let i = 0
+ let i = 0;
while (i < len) {
if (nums[i] === val) {
- nums[i] = nums[len - 1]
- len--
+ nums[i] = nums[len - 1];
+ len--;
} else {
- i++
+ i++;
}
}
- return len
+ return len;
};
var removeElement2 = function (nums, val) {
- let i = 0
+ let i = 0;
for (let j = 0; j < nums.length; j++) {
if (nums[j] !== val) {
- nums[i] = nums[j]
- i++
+ nums[i] = nums[j];
+ i++;
}
}
- return i
-}
+ return i;
+};
var removeElement = function (nums, val) {
let len = nums.length;
@@ -36,4 +36,4 @@ var removeElement = function (nums, val) {
}
}
return len;
-}
\ No newline at end of file
+};
diff --git a/solution/0000-0099/0028.Implement strStr()/README.md b/solution/0000-0099/0028.Implement strStr()/README.md
index e3b5a09c1020e..2add41571221e 100644
--- a/solution/0000-0099/0028.Implement strStr()/README.md
+++ b/solution/0000-0099/0028.Implement strStr()/README.md
@@ -1,8 +1,9 @@
# [28. 实现 strStr()](https://leetcode-cn.com/problems/implement-strstr)
-[English Version](/solution/0000-0099/0028.Implement%20strStr()/README_EN.md)
+[English Version]()
## 题目描述
+
实现 strStr() 函数。
@@ -26,15 +27,14 @@
对于本题而言,当 needle
是空字符串时我们应当返回 0 。这与C语言的 strstr() 以及 Java的 indexOf() 定义相符。
-
-
## 解法
-
+
### **Python3**
+
```python
@@ -42,6 +42,7 @@
```
### **Java**
+
```java
@@ -49,8 +50,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0028.Implement strStr()/README_EN.md b/solution/0000-0099/0028.Implement strStr()/README_EN.md
index d7c32e3e00626..b6929028eb663 100644
--- a/solution/0000-0099/0028.Implement strStr()/README_EN.md
+++ b/solution/0000-0099/0028.Implement strStr()/README_EN.md
@@ -1,20 +1,15 @@
# [28. Implement strStr()](https://leetcode.com/problems/implement-strstr)
-[中文文档](/solution/0000-0099/0028.Implement%20strStr()/README.md)
+[中文文档]()
## Description
-Implement strStr().
-
+Implement strStr().
Return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.
-
-
Example 1:
-
-
Input: haystack = "hello", needle = "ll"
@@ -23,12 +18,8 @@
-
-
Example 2:
-
-
Input: haystack = "aaaaa", needle = "bba"
@@ -37,24 +28,14 @@
-
-
Clarification:
-
-
What should we return when needle
is an empty string? This is a great question to ask during an interview.
-
-
For the purpose of this problem, we will return 0 when needle
is an empty string. This is consistent to C's strstr() and Java's indexOf().
-
-
-
## Solutions
-
### **Python3**
@@ -70,8 +51,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0028.Implement strStr()/Solution.js b/solution/0000-0099/0028.Implement strStr()/Solution.js
index 54dd21355df5d..76e29daee2181 100644
--- a/solution/0000-0099/0028.Implement strStr()/Solution.js
+++ b/solution/0000-0099/0028.Implement strStr()/Solution.js
@@ -4,19 +4,19 @@
* @return {number}
*/
var strStr = function (haystack, needle) {
- const slen = haystack.length
- const plen = needle.length
- if (slen == plen) {
- return haystack == needle ? 0 : -1
+ const slen = haystack.length;
+ const plen = needle.length;
+ if (slen == plen) {
+ return haystack == needle ? 0 : -1;
+ }
+ for (let i = 0; i <= slen - plen; i++) {
+ let j;
+ for (j = 0; j < plen; j++) {
+ if (haystack[i + j] != needle[j]) {
+ break;
+ }
}
- for (let i = 0; i <= slen - plen; i++) {
- let j
- for (j = 0; j < plen; j++) {
- if (haystack[i + j] != needle[j]) {
- break
- }
- }
- if (j == plen) return i
- }
- return -1
+ if (j == plen) return i;
+ }
+ return -1;
};
diff --git a/solution/0000-0099/0029.Divide Two Integers/README.md b/solution/0000-0099/0029.Divide Two Integers/README.md
index 3aec5adbe0599..a0d4110f34972 100644
--- a/solution/0000-0099/0029.Divide Two Integers/README.md
+++ b/solution/0000-0099/0029.Divide Two Integers/README.md
@@ -3,6 +3,7 @@
[English Version](/solution/0000-0099/0029.Divide%20Two%20Integers/README_EN.md)
## 题目描述
+
给定两个整数,被除数 dividend
和除数 divisor
。将两数相除,要求不使用乘法、除法和 mod 运算符。
@@ -34,15 +35,14 @@
假设我们的环境只能存储 32 位有符号整数,其数值范围是 [−231, 231 − 1]。本题中,如果除法结果溢出,则返回 231 − 1。
-
-
## 解法
-
+
### **Python3**
+
```python
@@ -50,6 +50,7 @@
```
### **Java**
+
```java
@@ -57,8 +58,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0029.Divide Two Integers/README_EN.md b/solution/0000-0099/0029.Divide Two Integers/README_EN.md
index a806a328ab9d6..41687328f3a76 100644
--- a/solution/0000-0099/0029.Divide Two Integers/README_EN.md
+++ b/solution/0000-0099/0029.Divide Two Integers/README_EN.md
@@ -3,6 +3,7 @@
[中文文档](/solution/0000-0099/0029.Divide%20Two%20Integers/README.md)
## Description
+
Given two integers dividend
and divisor
, divide two integers without using multiplication, division and mod operator.
Return the quotient after dividing dividend
by divisor
.
@@ -33,11 +34,8 @@
Assume we are dealing with an environment which could only store integers within the 32-bit signed integer range: [−231, 231 − 1]. For the purpose of this problem, assume that your function returns 231 − 1 when the division result overflows.
-
-
## Solutions
-
### **Python3**
@@ -53,8 +51,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0030.Substring with Concatenation of All Words/README.md b/solution/0000-0099/0030.Substring with Concatenation of All Words/README.md
index 304f4a3eff3ca..f609581f9f8d2 100644
--- a/solution/0000-0099/0030.Substring with Concatenation of All Words/README.md
+++ b/solution/0000-0099/0030.Substring with Concatenation of All Words/README.md
@@ -3,6 +3,7 @@
[English Version](/solution/0000-0099/0030.Substring%20with%20Concatenation%20of%20All%20Words/README_EN.md)
## 题目描述
+
给定一个字符串 s 和一些长度相同的单词 words。找出 s 中恰好可以由 words 中所有单词串联形成的子串的起始位置。
@@ -29,15 +30,14 @@
输出:[]
-
-
## 解法
-
+
### **Python3**
+
```python
@@ -45,6 +45,7 @@
```
### **Java**
+
```java
@@ -52,8 +53,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0030.Substring with Concatenation of All Words/README_EN.md b/solution/0000-0099/0030.Substring with Concatenation of All Words/README_EN.md
index 1172d9f0ac0c2..aea840fe735cc 100644
--- a/solution/0000-0099/0030.Substring with Concatenation of All Words/README_EN.md
+++ b/solution/0000-0099/0030.Substring with Concatenation of All Words/README_EN.md
@@ -3,6 +3,7 @@
[中文文档](/solution/0000-0099/0030.Substring%20with%20Concatenation%20of%20All%20Words/README.md)
## Description
+
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.
@@ -27,11 +28,8 @@ The output order does not matter, returning [9,0] is fine too.
Output: []
-
-
## Solutions
-
### **Python3**
@@ -47,8 +45,9 @@ The output order does not matter, returning [9,0] is fine too.
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0031.Next Permutation/README.md b/solution/0000-0099/0031.Next Permutation/README.md
index c66b99afa2c7d..f5db1fe7e7c5f 100644
--- a/solution/0000-0099/0031.Next Permutation/README.md
+++ b/solution/0000-0099/0031.Next Permutation/README.md
@@ -3,6 +3,7 @@
[English Version](/solution/0000-0099/0031.Next%20Permutation/README_EN.md)
## 题目描述
+
实现获取下一个排列的函数,算法需要将给定数字序列重新排列成字典序中下一个更大的排列。
@@ -15,15 +16,14 @@
3,2,1
→ 1,2,3
1,1,5
→ 1,5,1
-
-
## 解法
-
+
### **Python3**
+
```python
@@ -31,6 +31,7 @@
```
### **Java**
+
```java
@@ -38,8 +39,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0031.Next Permutation/README_EN.md b/solution/0000-0099/0031.Next Permutation/README_EN.md
index 8381cade5ecf9..46c660f584437 100644
--- a/solution/0000-0099/0031.Next Permutation/README_EN.md
+++ b/solution/0000-0099/0031.Next Permutation/README_EN.md
@@ -3,34 +3,23 @@
[中文文档](/solution/0000-0099/0031.Next%20Permutation/README.md)
## Description
-Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.
-
+Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.
If such arrangement is not possible, it must rearrange it as the lowest possible order (ie, sorted in ascending order).
-
-
The replacement must be in-place and use only constant extra memory.
-
-
Here are some examples. Inputs are in the left-hand column and its corresponding outputs are in the right-hand column.
-
-
1,2,3
→ 1,3,2
3,2,1
→ 1,2,3
1,1,5
→ 1,5,1
-
-
-
## Solutions
-
### **Python3**
@@ -46,8 +35,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0032.Longest Valid Parentheses/README.md b/solution/0000-0099/0032.Longest Valid Parentheses/README.md
index 00c203e45e961..cf52c62fa8557 100644
--- a/solution/0000-0099/0032.Longest Valid Parentheses/README.md
+++ b/solution/0000-0099/0032.Longest Valid Parentheses/README.md
@@ -3,6 +3,7 @@
[English Version](/solution/0000-0099/0032.Longest%20Valid%20Parentheses/README_EN.md)
## 题目描述
+
给定一个只包含 '('
和 ')'
的字符串,找出最长的包含有效括号的子串的长度。
@@ -20,15 +21,14 @@
解释: 最长有效括号子串为 "()()"
-
-
## 解法
-
+
### **Python3**
+
```python
@@ -36,6 +36,7 @@
```
### **Java**
+
```java
@@ -43,8 +44,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0032.Longest Valid Parentheses/README_EN.md b/solution/0000-0099/0032.Longest Valid Parentheses/README_EN.md
index 0ff90ff98bec8..f6f2412681c4a 100644
--- a/solution/0000-0099/0032.Longest Valid Parentheses/README_EN.md
+++ b/solution/0000-0099/0032.Longest Valid Parentheses/README_EN.md
@@ -3,14 +3,11 @@
[中文文档](/solution/0000-0099/0032.Longest%20Valid%20Parentheses/README.md)
## Description
-Given a string containing just the characters '('
and ')'
, find the length of the longest valid (well-formed) parentheses substring.
-
+Given a string containing just the characters '('
and ')'
, find the length of the longest valid (well-formed) parentheses substring.
Example 1:
-
-
Input: "(()"
@@ -21,12 +18,8 @@
-
-
Example 2:
-
-
Input: ")()())
"
@@ -37,12 +30,8 @@
-
-
-
## Solutions
-
### **Python3**
@@ -58,8 +47,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0033.Search in Rotated Sorted Array/README.md b/solution/0000-0099/0033.Search in Rotated Sorted Array/README.md
index dfe56d7946626..bbc59c10bb224 100644
--- a/solution/0000-0099/0033.Search in Rotated Sorted Array/README.md
+++ b/solution/0000-0099/0033.Search in Rotated Sorted Array/README.md
@@ -3,6 +3,7 @@
[English Version](/solution/0000-0099/0033.Search%20in%20Rotated%20Sorted%20Array/README_EN.md)
## 题目描述
+
假设按照升序排序的数组在预先未知的某个点上进行了旋转。
@@ -25,15 +26,14 @@
输入: nums = [4,5,6,7,0,1,2]
, target = 3
输出: -1
-
-
## 解法
-
+
### **Python3**
+
```python
@@ -41,6 +41,7 @@
```
### **Java**
+
```java
@@ -48,8 +49,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0033.Search in Rotated Sorted Array/README_EN.md b/solution/0000-0099/0033.Search in Rotated Sorted Array/README_EN.md
index 2242c164c026c..5769ad8add2c1 100644
--- a/solution/0000-0099/0033.Search in Rotated Sorted Array/README_EN.md
+++ b/solution/0000-0099/0033.Search in Rotated Sorted Array/README_EN.md
@@ -3,30 +3,19 @@
[中文文档](/solution/0000-0099/0033.Search%20in%20Rotated%20Sorted%20Array/README.md)
## Description
-Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.
-
+Suppose an array sorted in ascending order 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 target value to search. If found in the array return its index, otherwise return -1
.
-
-
You may assume no duplicate exists in the array.
-
-
Your algorithm's runtime complexity must be in the order of O(log n).
-
-
Example 1:
-
-
Input: nums = [4,5,6,7,0,1,2]
, target = 0
@@ -35,24 +24,16 @@
-
-
Example 2:
-
-
Input: nums = [4,5,6,7,0,1,2]
, target = 3
Output: -1
-
-
-
## Solutions
-
### **Python3**
@@ -68,8 +49,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0033.Search in Rotated Sorted Array/Solution.js b/solution/0000-0099/0033.Search in Rotated Sorted Array/Solution.js
index 21c2bccae9806..700b830e84cf7 100644
--- a/solution/0000-0099/0033.Search in Rotated Sorted Array/Solution.js
+++ b/solution/0000-0099/0033.Search in Rotated Sorted Array/Solution.js
@@ -4,10 +4,10 @@
* @return {number}
*/
var search = function (nums, target) {
- for (let i = 0; i < nums.length; i++) {
- if (nums[i] == target) {
- return i
- }
+ for (let i = 0; i < nums.length; i++) {
+ if (nums[i] == target) {
+ return i;
}
- return -1
-};
\ No newline at end of file
+ }
+ return -1;
+};
diff --git a/solution/0000-0099/0034.Find First and Last Position of Element in Sorted Array/README.md b/solution/0000-0099/0034.Find First and Last Position of Element in Sorted Array/README.md
index 88b2744f457d5..f323fcc1cf6cf 100644
--- a/solution/0000-0099/0034.Find First and Last Position of Element in Sorted Array/README.md
+++ b/solution/0000-0099/0034.Find First and Last Position of Element in Sorted Array/README.md
@@ -3,6 +3,7 @@
[English Version](/solution/0000-0099/0034.Find%20First%20and%20Last%20Position%20of%20Element%20in%20Sorted%20Array/README_EN.md)
## 题目描述
+
给定一个按照升序排列的整数数组 nums
,和一个目标值 target
。找出给定目标值在数组中的开始位置和结束位置。
@@ -20,15 +21,14 @@
输入: nums = [5,7,7,8,8,10]
, target = 6
输出: [-1,-1]
-
-
## 解法
-
+
### **Python3**
+
```python
@@ -36,6 +36,7 @@
```
### **Java**
+
```java
@@ -43,8 +44,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0034.Find First and Last Position of Element in Sorted Array/README_EN.md b/solution/0000-0099/0034.Find First and Last Position of Element in Sorted Array/README_EN.md
index f1b20977890d9..570c6d605f3b6 100644
--- a/solution/0000-0099/0034.Find First and Last Position of Element in Sorted Array/README_EN.md
+++ b/solution/0000-0099/0034.Find First and Last Position of Element in Sorted Array/README_EN.md
@@ -3,46 +3,31 @@
[中文文档](/solution/0000-0099/0034.Find%20First%20and%20Last%20Position%20of%20Element%20in%20Sorted%20Array/README.md)
## Description
-Given an array of integers nums
sorted in ascending order, find the starting and ending position of a given target
value.
-
+Given an array of integers nums
sorted in ascending order, 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).
-
-
If the target is not found in the array, return [-1, -1]
.
-
-
Example 1:
-
-
Input: nums = [5,7,7,8,8,10]
, target = 8
Output: [3,4]
-
-
Example 2:
-
-
Input: nums = [5,7,7,8,8,10]
, target = 6
Output: [-1,-1]
-
-
-
## Solutions
-
### **Python3**
@@ -58,8 +43,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0035.Search Insert Position/README.md b/solution/0000-0099/0035.Search Insert Position/README.md
index 1ae86d8f2e162..31f70eca0bda8 100644
--- a/solution/0000-0099/0035.Search Insert Position/README.md
+++ b/solution/0000-0099/0035.Search Insert Position/README.md
@@ -3,6 +3,7 @@
[English Version](/solution/0000-0099/0035.Search%20Insert%20Position/README_EN.md)
## 题目描述
+
给定一个排序数组和一个目标值,在数组中找到目标值,并返回其索引。如果目标值不存在于数组中,返回它将会被按顺序插入的位置。
@@ -32,15 +33,14 @@
输出: 0
-
-
## 解法
-
+
### **Python3**
+
```python
@@ -48,6 +48,7 @@
```
### **Java**
+
```java
@@ -55,8 +56,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0035.Search Insert Position/README_EN.md b/solution/0000-0099/0035.Search Insert Position/README_EN.md
index 8d3786f7fa664..780fa28dd26c2 100644
--- a/solution/0000-0099/0035.Search Insert Position/README_EN.md
+++ b/solution/0000-0099/0035.Search Insert Position/README_EN.md
@@ -3,18 +3,13 @@
[中文文档](/solution/0000-0099/0035.Search%20Insert%20Position/README.md)
## Description
-Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.
-
+Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.
You may assume no duplicates in the array.
-
-
Example 1:
-
-
Input: [1,3,5,6], 5
@@ -23,12 +18,8 @@
-
-
Example 2:
-
-
Input: [1,3,5,6], 2
@@ -37,12 +28,8 @@
-
-
Example 3:
-
-
Input: [1,3,5,6], 7
@@ -51,12 +38,8 @@
-
-
Example 4:
-
-
Input: [1,3,5,6], 0
@@ -65,12 +48,8 @@
-
-
-
## Solutions
-
### **Python3**
@@ -86,8 +65,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0035.Search Insert Position/Solution.js b/solution/0000-0099/0035.Search Insert Position/Solution.js
index 5d00ff46ede2c..6c844fd643c10 100644
--- a/solution/0000-0099/0035.Search Insert Position/Solution.js
+++ b/solution/0000-0099/0035.Search Insert Position/Solution.js
@@ -5,7 +5,7 @@ var searchInsert2 = function (nums, target) {
}
}
return nums.length;
-}
+};
var searchInsert = function (nums, target) {
let left = 0;
@@ -39,4 +39,4 @@ var searchInsert = function (nums, target) {
}
return left;
-}
\ No newline at end of file
+};
diff --git a/solution/0000-0099/0036.Valid Sudoku/README.md b/solution/0000-0099/0036.Valid Sudoku/README.md
index 6b4f19c849fcd..fbfba55c374fe 100644
--- a/solution/0000-0099/0036.Valid Sudoku/README.md
+++ b/solution/0000-0099/0036.Valid Sudoku/README.md
@@ -3,6 +3,7 @@
[English Version](/solution/0000-0099/0036.Valid%20Sudoku/README_EN.md)
## 题目描述
+
判断一个 9x9 的数独是否有效。只需要根据以下规则,验证已经填入的数字是否有效即可。
@@ -62,15 +63,14 @@
给定数独永远是 9x9
形式的。
-
-
## 解法
-
+
### **Python3**
+
```python
@@ -78,6 +78,7 @@
```
### **Java**
+
```java
@@ -85,8 +86,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0036.Valid Sudoku/README_EN.md b/solution/0000-0099/0036.Valid Sudoku/README_EN.md
index fe61a40292a75..0c466b501b984 100644
--- a/solution/0000-0099/0036.Valid Sudoku/README_EN.md
+++ b/solution/0000-0099/0036.Valid Sudoku/README_EN.md
@@ -3,36 +3,27 @@
[中文文档](/solution/0000-0099/0036.Valid%20Sudoku/README.md)
## Description
-Determine if a 9x9 Sudoku board is valid. Only the filled cells need to be validated according to the following rules:
-
+Determine if a 9x9 Sudoku board is valid. Only the filled cells need to be validated according to the following rules:
- - Each row must contain the digits
1-9
without repetition.
+ - Each row must contain the digits
1-9
without repetition.
- - Each column must contain the digits
1-9
without repetition.
+ - Each column must contain the digits
1-9
without repetition.
- - Each of the 9
3x3
sub-boxes of the grid must contain the digits 1-9
without repetition.
+ - Each of the 9
3x3
sub-boxes of the grid must contain the digits 1-9
without repetition.
-
-

A partially filled sudoku which is valid.
-
-
The Sudoku board could be partially filled, where empty cells are filled with the character '.'
.
-
-
Example 1:
-
-
Input:
@@ -63,12 +54,8 @@
-
-
Example 2:
-
-
Input:
@@ -103,30 +90,22 @@
-
-
Note:
-
-
- - A Sudoku board (partially filled) could be valid but is not necessarily solvable.
+ - A Sudoku board (partially filled) could be valid but is not necessarily solvable.
- - Only the filled cells need to be validated according to the mentioned rules.
+ - Only the filled cells need to be validated according to the mentioned rules.
- - The given board contain only digits
1-9
and the character '.'
.
+ - The given board contain only digits
1-9
and the character '.'
.
- - The given board size is always
9x9
.
+ - The given board size is always
9x9
.
-
-
-
## Solutions
-
### **Python3**
@@ -142,8 +121,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0036.Valid Sudoku/Solution.js b/solution/0000-0099/0036.Valid Sudoku/Solution.js
index 01e22e2ffb93f..a58a823d06f89 100644
--- a/solution/0000-0099/0036.Valid Sudoku/Solution.js
+++ b/solution/0000-0099/0036.Valid Sudoku/Solution.js
@@ -1,35 +1,40 @@
-const isValidSudoku = function(board){
+const isValidSudoku = function (board) {
let existed = new Set();
- for(let i = 0; i < 9; i++){
- for(let j = 0; j < 9; j++){
+ for (let i = 0; i < 9; i++) {
+ for (let j = 0; j < 9; j++) {
let number = board[i][j];
- if(board[i][j] !== '.'){
- if(existed.has(number + " in row " + i )||
- existed.has(number + ' in column ' + j) ||
- existed.has(number + 'in block ' + parseInt(i/3) + '-' + parseInt(j/3))){
- return false;
- }else{
- existed.add(number + " in row " + i );
- existed.add(number + ' in column ' + j);
- existed.add(number + 'in block ' + parseInt(i/3) + '-' + parseInt(j/3));
- }
+ if (board[i][j] !== ".") {
+ if (
+ existed.has(number + " in row " + i) ||
+ existed.has(number + " in column " + j) ||
+ existed.has(
+ number + "in block " + parseInt(i / 3) + "-" + parseInt(j / 3)
+ )
+ ) {
+ return false;
+ } else {
+ existed.add(number + " in row " + i);
+ existed.add(number + " in column " + j);
+ existed.add(
+ number + "in block " + parseInt(i / 3) + "-" + parseInt(j / 3)
+ );
+ }
}
}
}
return true;
};
-
/**
* @param {character[][]} board
* @return {boolean}
*/
-const isValidSudoku2 = function(board){
- function lineTest(arr){
- for(let i = 0; i < 9; i++){
- for(let j = 0; j < 9; j++){
- for(let k = j+1; k < 9; k++){
- if(arr[i][j] === arr[i][k] && arr[i][j] !== '.'){
+const isValidSudoku2 = function (board) {
+ function lineTest(arr) {
+ for (let i = 0; i < 9; i++) {
+ for (let j = 0; j < 9; j++) {
+ for (let k = j + 1; k < 9; k++) {
+ if (arr[i][j] === arr[i][k] && arr[i][j] !== ".") {
return false;
}
}
@@ -37,12 +42,11 @@ const isValidSudoku2 = function(board){
}
return true;
}
- function columnTest(arr){
- for(let i = 0; i < 9; i++){
- for(let j = 0; j < 9;j++){
- for(let k = j+1; k < 9; k++){
- if(arr[j][i] === arr[k][i] && arr[j][i] !== '.'){
-
+ function columnTest(arr) {
+ for (let i = 0; i < 9; i++) {
+ for (let j = 0; j < 9; j++) {
+ for (let k = j + 1; k < 9; k++) {
+ if (arr[j][i] === arr[k][i] && arr[j][i] !== ".") {
return false;
}
}
@@ -50,27 +54,35 @@ const isValidSudoku2 = function(board){
}
return true;
}
- function squareTest(arr){
- let p = [[1,1],[1,4],[1,7],
- [4,1],[4,4],[4,7],
- [7,1],[7,4],[7,7]];
-
- for(let i = 0; i < p.length; i++){
+ function squareTest(arr) {
+ let p = [
+ [1, 1],
+ [1, 4],
+ [1, 7],
+ [4, 1],
+ [4, 4],
+ [4, 7],
+ [7, 1],
+ [7, 4],
+ [7, 7],
+ ];
+
+ for (let i = 0; i < p.length; i++) {
let a = [];
let x = p[i][0];
let y = p[i][1];
- a.push(arr[x-1][y-1]);
- a.push(arr[x-1][y]);
- a.push(arr[x-1][y+1]);
- a.push(arr[x][y-1]);
+ a.push(arr[x - 1][y - 1]);
+ a.push(arr[x - 1][y]);
+ a.push(arr[x - 1][y + 1]);
+ a.push(arr[x][y - 1]);
a.push(arr[x][y]);
- a.push(arr[x][y+1]);
- a.push(arr[x+1][y-1]);
- a.push(arr[x+1][y]);
- a.push(arr[x+1][y+1]);
- for(let j = 0; j < a.length; j++){
- for(let k = j+1; k < a.length; k++){
- if(a[j] === a[k] && a[j] !== '.'){
+ a.push(arr[x][y + 1]);
+ a.push(arr[x + 1][y - 1]);
+ a.push(arr[x + 1][y]);
+ a.push(arr[x + 1][y + 1]);
+ for (let j = 0; j < a.length; j++) {
+ for (let k = j + 1; k < a.length; k++) {
+ if (a[j] === a[k] && a[j] !== ".") {
return false;
}
}
@@ -78,5 +90,5 @@ const isValidSudoku2 = function(board){
}
return true;
}
- return lineTest(board)&&columnTest(board)&&squareTest(board);
+ return lineTest(board) && columnTest(board) && squareTest(board);
};
diff --git a/solution/0000-0099/0037.Sudoku Solver/README.md b/solution/0000-0099/0037.Sudoku Solver/README.md
index 980e8751c8e92..7550445cbc3e6 100644
--- a/solution/0000-0099/0037.Sudoku Solver/README.md
+++ b/solution/0000-0099/0037.Sudoku Solver/README.md
@@ -3,6 +3,7 @@
[English Version](/solution/0000-0099/0037.Sudoku%20Solver/README_EN.md)
## 题目描述
+
编写一个程序,通过已填充的空格来解决数独问题。
@@ -32,15 +33,14 @@
给定数独永远是 9x9
形式的。
-
-
## 解法
-
+
### **Python3**
+
```python
@@ -48,6 +48,7 @@
```
### **Java**
+
```java
@@ -55,8 +56,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0037.Sudoku Solver/README_EN.md b/solution/0000-0099/0037.Sudoku Solver/README_EN.md
index 4088a6d7bd70e..df04bec6cf58d 100644
--- a/solution/0000-0099/0037.Sudoku Solver/README_EN.md
+++ b/solution/0000-0099/0037.Sudoku Solver/README_EN.md
@@ -3,62 +3,45 @@
[中文文档](/solution/0000-0099/0037.Sudoku%20Solver/README.md)
## Description
-Write a program to solve a Sudoku puzzle by filling the empty cells.
-
+Write a program to solve a Sudoku puzzle by filling the empty cells.
A sudoku solution must satisfy all of the following rules:
-
-
- - Each of the digits
1-9
must occur exactly once in each row.
+ - Each of the digits
1-9
must occur exactly once in each row.
- - Each of the digits
1-9
must occur exactly once in each column.
+ - Each of the digits
1-9
must occur exactly once in each column.
- - Each of the the digits
1-9
must occur exactly once in each of the 9 3x3
sub-boxes of the grid.
+ - Each of the the digits
1-9
must occur exactly once in each of the 9 3x3
sub-boxes of the grid.
-
-
Empty cells are indicated by the character '.'
.
-
-

A sudoku puzzle...
-
-

...and its solution numbers marked in red.
-
-
Note:
-
-
- - The given board contain only digits
1-9
and the character '.'
.
+ - The given board contain only digits
1-9
and the character '.'
.
- - You may assume that the given Sudoku puzzle will have a single unique solution.
+ - You may assume that the given Sudoku puzzle will have a single unique solution.
- - The given board size is always
9x9
.
+ - The given board size is always
9x9
.
-
-
-
## Solutions
-
### **Python3**
@@ -74,8 +57,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0038.Count and Say/README.md b/solution/0000-0099/0038.Count and Say/README.md
index 58129268458d7..3ff853b17300e 100644
--- a/solution/0000-0099/0038.Count and Say/README.md
+++ b/solution/0000-0099/0038.Count and Say/README.md
@@ -3,6 +3,7 @@
[English Version](/solution/0000-0099/0038.Count%20and%20Say/README_EN.md)
## 题目描述
+
「外观数列」是一个整数序列,从数字 1 开始,序列中的每一项都是对前一项的描述。前五项如下:
@@ -35,15 +36,14 @@
输出: "1211"
解释:当 n = 3 时,序列是 "21",其中我们有 "2" 和 "1" 两组,"2" 可以读作 "12",也就是出现频次 = 1 而 值 = 2;类似 "1" 可以读作 "11"。所以答案是 "12" 和 "11" 组合在一起,也就是 "1211"。
-
-
## 解法
-
+
### **Python3**
+
```python
@@ -51,6 +51,7 @@
```
### **Java**
+
```java
@@ -58,8 +59,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0038.Count and Say/README_EN.md b/solution/0000-0099/0038.Count and Say/README_EN.md
index c0a84ccd753c2..51154c70db164 100644
--- a/solution/0000-0099/0038.Count and Say/README_EN.md
+++ b/solution/0000-0099/0038.Count and Say/README_EN.md
@@ -3,6 +3,7 @@
[中文文档](/solution/0000-0099/0038.Count%20and%20Say/README.md)
## Description
+
The count-and-say sequence is the sequence of integers with the first five terms as following:
@@ -39,11 +40,8 @@
Explanation: For n = 3 the term was "21" in which we have two groups "2" and "1", "2" can be read as "12" which means frequency = 1 and value = 2, the same way "1" is read as "11", so the answer is the concatenation of "12" and "11" which is "1211".
-
-
## Solutions
-
### **Python3**
@@ -59,8 +57,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0038.Count and Say/Solution.js b/solution/0000-0099/0038.Count and Say/Solution.js
index e01af9d715166..972b40d35ff49 100644
--- a/solution/0000-0099/0038.Count and Say/Solution.js
+++ b/solution/0000-0099/0038.Count and Say/Solution.js
@@ -1,13 +1,15 @@
-const countAndSay = function(n){
- let s = '1';
+const countAndSay = function (n) {
+ let s = "1";
- for(let i = 2; i <= n; i++){
- let count = 1, str = '', len = s.length;
+ for (let i = 2; i <= n; i++) {
+ let count = 1,
+ str = "",
+ len = s.length;
- for(let j = 0 ; j < len; j++){
- if(j < len - 1 && s[j] === s[j + 1]){
+ for (let j = 0; j < len; j++) {
+ if (j < len - 1 && s[j] === s[j + 1]) {
count++;
- }else{
+ } else {
str += `${count}${s[j]}`;
count = 1;
}
@@ -15,4 +17,4 @@ const countAndSay = function(n){
s = str;
}
return s;
-}
\ No newline at end of file
+};
diff --git a/solution/0000-0099/0039.Combination Sum/README.md b/solution/0000-0099/0039.Combination Sum/README.md
index 1444579abe360..e1544424647a4 100644
--- a/solution/0000-0099/0039.Combination Sum/README.md
+++ b/solution/0000-0099/0039.Combination Sum/README.md
@@ -3,6 +3,7 @@
[English Version](/solution/0000-0099/0039.Combination%20Sum/README_EN.md)
## 题目描述
+
给定一个无重复元素的数组 candidates
和一个目标数 target
,找出 candidates
中所有可以使数字和为 target
的组合。
@@ -35,15 +36,14 @@
[3,5]
]
-
-
## 解法
-
+
### **Python3**
+
```python
@@ -51,6 +51,7 @@
```
### **Java**
+
```java
@@ -58,8 +59,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0039.Combination Sum/README_EN.md b/solution/0000-0099/0039.Combination Sum/README_EN.md
index 544e68dc081f7..b4e940f3e77c5 100644
--- a/solution/0000-0099/0039.Combination Sum/README_EN.md
+++ b/solution/0000-0099/0039.Combination Sum/README_EN.md
@@ -3,32 +3,23 @@
[中文文档](/solution/0000-0099/0039.Combination%20Sum/README.md)
## Description
-Given a set of candidate numbers (candidates
) (without duplicates) and a target number (target
), find all unique combinations in candidates
where the candidate numbers sums to target
.
-
+Given a set of candidate numbers (candidates
) (without duplicates) and a target number (target
), find all unique combinations in candidates
where the candidate numbers sums to target
.
The same repeated number may be chosen from candidates
unlimited number of times.
-
-
Note:
-
-
- - All numbers (including
target
) will be positive integers.
+ - All numbers (including
target
) will be positive integers.
- - The solution set must not contain duplicate combinations.
+ - The solution set must not contain duplicate combinations.
-
-
Example 1:
-
-
Input: candidates = [2,3,6,7],
target = 7
,
@@ -45,12 +36,8 @@
-
-
Example 2:
-
-
Input: candidates = [2,3,5],
target = 8,
@@ -69,12 +56,8 @@
-
-
-
## Solutions
-
### **Python3**
@@ -90,8 +73,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0040.Combination Sum II/README.md b/solution/0000-0099/0040.Combination Sum II/README.md
index b6010b3eaed33..d3186a978c4f1 100644
--- a/solution/0000-0099/0040.Combination Sum II/README.md
+++ b/solution/0000-0099/0040.Combination Sum II/README.md
@@ -3,6 +3,7 @@
[English Version](/solution/0000-0099/0040.Combination%20Sum%20II/README_EN.md)
## 题目描述
+
给定一个数组 candidates
和一个目标数 target
,找出 candidates
中所有可以使数字和为 target
的组合。
@@ -36,15 +37,14 @@
[5]
]
-
-
## 解法
-
+
### **Python3**
+
```python
@@ -52,6 +52,7 @@
```
### **Java**
+
```java
@@ -59,8 +60,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0040.Combination Sum II/README_EN.md b/solution/0000-0099/0040.Combination Sum II/README_EN.md
index 0c158cbe7be34..78c36fcaf4e8f 100644
--- a/solution/0000-0099/0040.Combination Sum II/README_EN.md
+++ b/solution/0000-0099/0040.Combination Sum II/README_EN.md
@@ -3,32 +3,23 @@
[中文文档](/solution/0000-0099/0040.Combination%20Sum%20II/README.md)
## Description
-Given a collection of candidate numbers (candidates
) and a target number (target
), find all unique combinations in candidates
where the candidate numbers sums to target
.
-
+Given a collection of candidate numbers (candidates
) and a target number (target
), find all unique combinations in candidates
where the candidate numbers sums to target
.
Each number in candidates
may only be used once in the combination.
-
-
Note:
-
-
- - All numbers (including
target
) will be positive integers.
+ - All numbers (including
target
) will be positive integers.
- - The solution set must not contain duplicate combinations.
+ - The solution set must not contain duplicate combinations.
-
-
Example 1:
-
-
Input: candidates = [10,1,2,7,6,1,5]
, target = 8
,
@@ -49,12 +40,8 @@
-
-
Example 2:
-
-
Input: candidates = [2,5,2,1,2], target = 5,
@@ -71,12 +58,8 @@
-
-
-
## Solutions
-
### **Python3**
@@ -92,8 +75,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0041.First Missing Positive/README.md b/solution/0000-0099/0041.First Missing Positive/README.md
index 227250188afcf..7cf4514b677eb 100644
--- a/solution/0000-0099/0041.First Missing Positive/README.md
+++ b/solution/0000-0099/0041.First Missing Positive/README.md
@@ -3,6 +3,7 @@
[English Version](/solution/0000-0099/0041.First%20Missing%20Positive/README_EN.md)
## 题目描述
+
给定一个未排序的整数数组,找出其中没有出现的最小的正整数。
@@ -28,15 +29,14 @@
你的算法的时间复杂度应为O(n),并且只能使用常数级别的空间。
-
-
## 解法
-
+
### **Python3**
+
```python
@@ -44,6 +44,7 @@
```
### **Java**
+
```java
@@ -51,8 +52,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0041.First Missing Positive/README_EN.md b/solution/0000-0099/0041.First Missing Positive/README_EN.md
index 84cc4d17b5359..6ea33b831084d 100644
--- a/solution/0000-0099/0041.First Missing Positive/README_EN.md
+++ b/solution/0000-0099/0041.First Missing Positive/README_EN.md
@@ -3,14 +3,11 @@
[中文文档](/solution/0000-0099/0041.First%20Missing%20Positive/README.md)
## Description
-Given an unsorted integer array, find the smallest missing positive integer.
-
+Given an unsorted integer array, find the smallest missing positive integer.
Example 1:
-
-
Input: [1,2,0]
@@ -19,12 +16,8 @@ Output: 3
-
-
Example 2:
-
-
Input: [3,4,-1,1]
@@ -33,12 +26,8 @@ Output: 2
-
-
Example 3:
-
-
Input: [7,8,9,11,12]
@@ -47,20 +36,12 @@ Output: 1
-
-
Note:
-
-
Your algorithm should run in O(n) time and uses constant extra space.
-
-
-
## Solutions
-
### **Python3**
@@ -76,8 +57,9 @@ Output: 1
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0042.Trapping Rain Water/README.md b/solution/0000-0099/0042.Trapping Rain Water/README.md
index ec7346b1ae40a..472aae905fae1 100644
--- a/solution/0000-0099/0042.Trapping Rain Water/README.md
+++ b/solution/0000-0099/0042.Trapping Rain Water/README.md
@@ -3,6 +3,7 @@
[English Version](/solution/0000-0099/0042.Trapping%20Rain%20Water/README_EN.md)
## 题目描述
+
给定 n 个非负整数表示每个宽度为 1 的柱子的高度图,计算按此排列的柱子,下雨之后能接多少雨水。
@@ -15,15 +16,14 @@
输入: [0,1,0,2,1,0,1,3,2,1,2,1]
输出: 6
-
-
## 解法
-
+
### **Python3**
+
```python
@@ -31,6 +31,7 @@
```
### **Java**
+
```java
@@ -38,8 +39,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0042.Trapping Rain Water/README_EN.md b/solution/0000-0099/0042.Trapping Rain Water/README_EN.md
index fa4db84224ef2..3dede449e9a6d 100644
--- a/solution/0000-0099/0042.Trapping Rain Water/README_EN.md
+++ b/solution/0000-0099/0042.Trapping Rain Water/README_EN.md
@@ -3,31 +3,23 @@
[中文文档](/solution/0000-0099/0042.Trapping%20Rain%20Water/README.md)
## Description
-Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.
+Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.

The above elevation map is represented by array [0,1,0,2,1,0,1,3,2,1,2,1]. In this case, 6 units of rain water (blue section) are being trapped. Thanks Marcos for contributing this image!
-
-
Example:
-
-
Input: [0,1,0,2,1,0,1,3,2,1,2,1]
Output: 6
-
-
-
## Solutions
-
### **Python3**
@@ -43,8 +35,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0043.Multiply Strings/README.md b/solution/0000-0099/0043.Multiply Strings/README.md
index 8335a9204a20b..57cc3dcaef206 100644
--- a/solution/0000-0099/0043.Multiply Strings/README.md
+++ b/solution/0000-0099/0043.Multiply Strings/README.md
@@ -3,6 +3,7 @@
[English Version](/solution/0000-0099/0043.Multiply%20Strings/README_EN.md)
## 题目描述
+
给定两个以字符串形式表示的非负整数 num1
和 num2
,返回 num1
和 num2
的乘积,它们的乘积也表示为字符串形式。
@@ -25,15 +26,14 @@
不能使用任何标准库的大数类型(比如 BigInteger)或直接将输入转换为整数来处理。
-
-
## 解法
-
+
### **Python3**
+
```python
@@ -41,6 +41,7 @@
```
### **Java**
+
```java
@@ -48,8 +49,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0043.Multiply Strings/README_EN.md b/solution/0000-0099/0043.Multiply Strings/README_EN.md
index e8d76e0bb89d9..eab55338c3bcb 100644
--- a/solution/0000-0099/0043.Multiply Strings/README_EN.md
+++ b/solution/0000-0099/0043.Multiply Strings/README_EN.md
@@ -3,26 +3,19 @@
[中文文档](/solution/0000-0099/0043.Multiply%20Strings/README.md)
## Description
-Given two non-negative integers num1
and num2
represented as strings, return the product of num1
and num2
, also represented as a string.
-
+Given two non-negative integers num1
and num2
represented as strings, return the product of num1
and num2
, also represented as a string.
Example 1:
-
-
Input: num1 = "2", num2 = "3"
Output: "6"
-
-
Example 2:
-
-
Input: num1 = "123", num2 = "456"
@@ -31,30 +24,22 @@
-
-
Note:
-
-
- - The length of both
num1
and num2
is < 110.
+ - The length of both
num1
and num2
is < 110.
- - Both
num1
and num2
contain only digits 0-9
.
+ - Both
num1
and num2
contain only digits 0-9
.
- - Both
num1
and num2
do not contain any leading zero, except the number 0 itself.
+ - Both
num1
and num2
do not contain any leading zero, except the number 0 itself.
- - You must not use any built-in BigInteger library or convert the inputs to integer directly.
+ - You must not use any built-in BigInteger library or convert the inputs to integer directly.
-
-
-
## Solutions
-
### **Python3**
@@ -70,8 +55,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0044.Wildcard Matching/README.md b/solution/0000-0099/0044.Wildcard Matching/README.md
index 862c23b5ea5e8..4e5dec28ab1f7 100644
--- a/solution/0000-0099/0044.Wildcard Matching/README.md
+++ b/solution/0000-0099/0044.Wildcard Matching/README.md
@@ -3,6 +3,7 @@
[English Version](/solution/0000-0099/0044.Wildcard%20Matching/README_EN.md)
## 题目描述
+
给定一个字符串 (s
) 和一个字符模式 (p
) ,实现一个支持 '?'
和 '*'
的通配符匹配。
@@ -61,15 +62,14 @@ s = "acdcb"
p = "a*c?b"
输入: false
-
-
## 解法
-
+
### **Python3**
+
```python
@@ -77,6 +77,7 @@ p = "a*c?b"
```
### **Java**
+
```java
@@ -84,8 +85,9 @@ p = "a*c?b"
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0044.Wildcard Matching/README_EN.md b/solution/0000-0099/0044.Wildcard Matching/README_EN.md
index 2112e311a5b55..d5cda96354545 100644
--- a/solution/0000-0099/0044.Wildcard Matching/README_EN.md
+++ b/solution/0000-0099/0044.Wildcard Matching/README_EN.md
@@ -3,9 +3,8 @@
[中文文档](/solution/0000-0099/0044.Wildcard%20Matching/README.md)
## Description
-Given an input string (s
) and a pattern (p
), implement wildcard pattern matching with support for '?'
and '*'
.
-
+Given an input string (s
) and a pattern (p
), implement wildcard pattern matching with support for '?'
and '*'
.
@@ -15,30 +14,20 @@
-
-
The matching should cover the entire input string (not partial).
-
-
Note:
-
-
- s
could be empty and contains only lowercase letters a-z
.
+ s
could be empty and contains only lowercase letters a-z
.
- p
could be empty and contains only lowercase letters a-z
, and characters like ?
or *
.
+ p
could be empty and contains only lowercase letters a-z
, and characters like ?
or *
.
-
-
Example 1:
-
-
Input:
@@ -53,12 +42,8 @@ p = "a"
-
-
Example 2:
-
-
Input:
@@ -73,12 +58,8 @@ p = "*"
-
-
Example 3:
-
-
Input:
@@ -93,12 +74,8 @@ p = "?a"
-
-
Example 4:
-
-
Input:
@@ -113,12 +90,8 @@ p = "*a*b"
-
-
Example 5:
-
-
Input:
@@ -131,12 +104,8 @@ p = "a*c?b"
-
-
-
## Solutions
-
### **Python3**
@@ -152,8 +121,9 @@ p = "a*c?b"
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0045.Jump Game II/README.md b/solution/0000-0099/0045.Jump Game II/README.md
index 127ded5416fba..061d1535cb267 100644
--- a/solution/0000-0099/0045.Jump Game II/README.md
+++ b/solution/0000-0099/0045.Jump Game II/README.md
@@ -3,6 +3,7 @@
[English Version](/solution/0000-0099/0045.Jump%20Game%20II/README_EN.md)
## 题目描述
+
给定一个非负整数数组,你最初位于数组的第一个位置。
@@ -22,15 +23,14 @@
假设你总是可以到达数组的最后一个位置。
-
-
## 解法
-
+
### **Python3**
+
```python
@@ -38,6 +38,7 @@
```
### **Java**
+
```java
@@ -45,8 +46,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0045.Jump Game II/README_EN.md b/solution/0000-0099/0045.Jump Game II/README_EN.md
index 1933cf0a72b26..66a240733e3c7 100644
--- a/solution/0000-0099/0045.Jump Game II/README_EN.md
+++ b/solution/0000-0099/0045.Jump Game II/README_EN.md
@@ -3,22 +3,15 @@
[中文文档](/solution/0000-0099/0045.Jump%20Game%20II/README.md)
## Description
-Given an array of non-negative integers, you are initially positioned at the first index of the array.
-
+Given an array of non-negative integers, you are initially positioned at the first index of the array.
Each element in the array represents your maximum jump length at that position.
-
-
Your goal is to reach the last index in the minimum number of jumps.
-
-
Example:
-
-
Input: [2,3,1,1,4]
@@ -29,20 +22,12 @@
Jump 1 step from index 0 to 1, then 3 steps to the last index.
-
-
Note:
-
-
You can assume that you can always reach the last index.
-
-
-
## Solutions
-
### **Python3**
@@ -58,8 +43,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0046.Permutations/README.md b/solution/0000-0099/0046.Permutations/README.md
index 3b5b5c95aaa1b..e5bf4398b1cda 100644
--- a/solution/0000-0099/0046.Permutations/README.md
+++ b/solution/0000-0099/0046.Permutations/README.md
@@ -3,6 +3,7 @@
[English Version](/solution/0000-0099/0046.Permutations/README_EN.md)
## 题目描述
+
给定一个没有重复数字的序列,返回其所有可能的全排列。
@@ -19,15 +20,14 @@
[3,2,1]
]
-
-
## 解法
-
+
### **Python3**
+
```python
@@ -35,6 +35,7 @@
```
### **Java**
+
```java
@@ -42,8 +43,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0046.Permutations/README_EN.md b/solution/0000-0099/0046.Permutations/README_EN.md
index b84e6350e6baa..c39f131927679 100644
--- a/solution/0000-0099/0046.Permutations/README_EN.md
+++ b/solution/0000-0099/0046.Permutations/README_EN.md
@@ -3,14 +3,11 @@
[中文文档](/solution/0000-0099/0046.Permutations/README.md)
## Description
-Given a collection of distinct integers, return all possible permutations.
-
+Given a collection of distinct integers, return all possible permutations.
Example:
-
-
Input: [1,2,3]
@@ -35,12 +32,8 @@
-
-
-
## Solutions
-
### **Python3**
@@ -56,8 +49,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0047.Permutations II/README.md b/solution/0000-0099/0047.Permutations II/README.md
index 283d6752ca984..804ef7728ed32 100644
--- a/solution/0000-0099/0047.Permutations II/README.md
+++ b/solution/0000-0099/0047.Permutations II/README.md
@@ -3,6 +3,7 @@
[English Version](/solution/0000-0099/0047.Permutations%20II/README_EN.md)
## 题目描述
+
给定一个可包含重复数字的序列,返回所有不重复的全排列。
@@ -16,15 +17,14 @@
[2,1,1]
]
-
-
## 解法
-
+
### **Python3**
+
```python
@@ -32,6 +32,7 @@
```
### **Java**
+
```java
@@ -39,8 +40,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0047.Permutations II/README_EN.md b/solution/0000-0099/0047.Permutations II/README_EN.md
index da96d7b4f87f9..9c2bd8ca301f5 100644
--- a/solution/0000-0099/0047.Permutations II/README_EN.md
+++ b/solution/0000-0099/0047.Permutations II/README_EN.md
@@ -3,14 +3,11 @@
[中文文档](/solution/0000-0099/0047.Permutations%20II/README.md)
## Description
-Given a collection of numbers that might contain duplicates, return all possible unique permutations.
-
+Given a collection of numbers that might contain duplicates, return all possible unique permutations.
Example:
-
-
Input: [1,1,2]
@@ -29,12 +26,8 @@
-
-
-
## Solutions
-
### **Python3**
@@ -50,8 +43,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0048.Rotate Image/README.md b/solution/0000-0099/0048.Rotate Image/README.md
index 36e29256a677d..4d93e7f186438 100644
--- a/solution/0000-0099/0048.Rotate Image/README.md
+++ b/solution/0000-0099/0048.Rotate Image/README.md
@@ -3,6 +3,7 @@
[English Version](/solution/0000-0099/0048.Rotate%20Image/README_EN.md)
## 题目描述
+
给定一个 n × n 的二维矩阵表示一个图像。
@@ -48,15 +49,14 @@
]
-
-
## 解法
-
+
### **Python3**
+
```python
@@ -64,6 +64,7 @@
```
### **Java**
+
```java
@@ -71,8 +72,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0048.Rotate Image/README_EN.md b/solution/0000-0099/0048.Rotate Image/README_EN.md
index 6fe51db03f335..4c8ff2b21976d 100644
--- a/solution/0000-0099/0048.Rotate Image/README_EN.md
+++ b/solution/0000-0099/0048.Rotate Image/README_EN.md
@@ -3,26 +3,17 @@
[中文文档](/solution/0000-0099/0048.Rotate%20Image/README.md)
## Description
-You are given an n x n 2D matrix representing an image.
-
+You are given an n x n 2D matrix representing an image.
Rotate the image by 90 degrees (clockwise).
-
-
Note:
-
-
You have to rotate the image in-place, which means you have to modify the input 2D matrix directly. DO NOT allocate another 2D matrix and do the rotation.
-
-
Example 1:
-
-
Given input matrix =
@@ -53,12 +44,8 @@ rotate the input matrix in-place such that it becomes:
-
-
Example 2:
-
-
Given input matrix =
@@ -93,12 +80,8 @@ rotate the input matrix in-place such that it becomes:
-
-
-
## Solutions
-
### **Python3**
@@ -114,8 +97,9 @@ rotate the input matrix in-place such that it becomes:
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0048.Rotate Image/Solution.js b/solution/0000-0099/0048.Rotate Image/Solution.js
index 25c34a02bab71..168962e3e1f82 100644
--- a/solution/0000-0099/0048.Rotate Image/Solution.js
+++ b/solution/0000-0099/0048.Rotate Image/Solution.js
@@ -2,38 +2,38 @@
* @param {number[][]} matrix
* @return {void} Do not return anything, modify matrix in-place instead.
*/
-const rotate1 = function(matrix) {
+const rotate1 = function (matrix) {
// function swap(x,y){
// console.log(x,y);
// let z = x;
// x = y;
// y = z;
// }
- for(let i = 0; i < matrix.length; i++){
- for(let j = 0; j <= i; j++){
+ for (let i = 0; i < matrix.length; i++) {
+ for (let j = 0; j <= i; j++) {
// swap(matrix[i][j],matrix[j][i]);
// let t = matrix[i][j];
// matrix[i][j] = matrix[j][i];
// matrix[j][i] = t;
- [matrix[i][j],matrix[j][i]] = [matrix[j][i],matrix[i][j]];
+ [matrix[i][j], matrix[j][i]] = [matrix[j][i], matrix[i][j]];
}
}
- for(let i = 0, j = matrix.length -1; i < j; i++, j--){
- for(let k = 0; k < matrix.length; k++){
+ for (let i = 0, j = matrix.length - 1; i < j; i++, j--) {
+ for (let k = 0; k < matrix.length; k++) {
// swap(matrix[k][i], matrix[k][j]);
// let t = matrix[k][i];
// matrix[k][i] = matrix[k][j];
// matrix[k][j] = t;
- [matrix[k][i], matrix[k][j]] = [matrix[k][j],matrix[k][i]];
+ [matrix[k][i], matrix[k][j]] = [matrix[k][j], matrix[k][i]];
}
}
};
-const rotate = function(matrix){
+const rotate = function (matrix) {
matrix = matrix.reverse();
- for(let i = 0 ; i < matrix.length; i++){
- for(let j = 0; j < i; j++){
- [matrix[i][j],matrix[j][i]] = [matrix[j][i],matrix[i][j]];
+ for (let i = 0; i < matrix.length; i++) {
+ for (let j = 0; j < i; j++) {
+ [matrix[i][j], matrix[j][i]] = [matrix[j][i], matrix[i][j]];
}
}
-};
\ No newline at end of file
+};
diff --git a/solution/0000-0099/0049.Group Anagrams/README.md b/solution/0000-0099/0049.Group Anagrams/README.md
index 723543ab86e57..2ee9260c39c4b 100644
--- a/solution/0000-0099/0049.Group Anagrams/README.md
+++ b/solution/0000-0099/0049.Group Anagrams/README.md
@@ -3,6 +3,7 @@
[English Version](/solution/0000-0099/0049.Group%20Anagrams/README_EN.md)
## 题目描述
+
给定一个字符串数组,将字母异位词组合在一起。字母异位词指字母相同,但排列不同的字符串。
@@ -23,15 +24,14 @@
不考虑答案输出的顺序。
-
-
## 解法
-
+
### **Python3**
+
```python
@@ -39,6 +39,7 @@
```
### **Java**
+
```java
@@ -46,8 +47,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0049.Group Anagrams/README_EN.md b/solution/0000-0099/0049.Group Anagrams/README_EN.md
index c2334b115af1f..9af5a52aab2ea 100644
--- a/solution/0000-0099/0049.Group Anagrams/README_EN.md
+++ b/solution/0000-0099/0049.Group Anagrams/README_EN.md
@@ -3,14 +3,11 @@
[中文文档](/solution/0000-0099/0049.Group%20Anagrams/README.md)
## Description
-Given an array of strings, group anagrams together.
-
+Given an array of strings, group anagrams together.
Example:
-
-
Input: ["eat", "tea", "tan", "ate", "nat", "bat"]
,
@@ -27,26 +24,18 @@
]
-
-
Note:
-
-
- - All inputs will be in lowercase.
+ - All inputs will be in lowercase.
- - The order of your output does not matter.
+ - The order of your output does not matter.
-
-
-
## Solutions
-
### **Python3**
@@ -62,8 +51,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0050.Pow(x, n)/README.md b/solution/0000-0099/0050.Pow(x, n)/README.md
index 319058ca56745..e0df3ebe2122a 100644
--- a/solution/0000-0099/0050.Pow(x, n)/README.md
+++ b/solution/0000-0099/0050.Pow(x, n)/README.md
@@ -1,8 +1,9 @@
# [50. Pow(x, n)](https://leetcode-cn.com/problems/powx-n)
-[English Version](/solution/0000-0099/0050.Pow(x,%20n)/README_EN.md)
+[English Version]()
## 题目描述
+
实现 pow(x, n) ,即计算 x 的 n 次幂函数。
@@ -31,15 +32,14 @@
n 是 32 位有符号整数,其数值范围是 [−231, 231 − 1] 。
-
-
## 解法
-
+
### **Python3**
+
```python
@@ -47,6 +47,7 @@
```
### **Java**
+
```java
@@ -54,8 +55,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0050.Pow(x, n)/README_EN.md b/solution/0000-0099/0050.Pow(x, n)/README_EN.md
index 5e4afb3a7cb2e..bc0c8e5012c28 100644
--- a/solution/0000-0099/0050.Pow(x, n)/README_EN.md
+++ b/solution/0000-0099/0050.Pow(x, n)/README_EN.md
@@ -1,16 +1,13 @@
# [50. Pow(x, n)](https://leetcode.com/problems/powx-n)
-[中文文档](/solution/0000-0099/0050.Pow(x,%20n)/README.md)
+[中文文档]()
## Description
-Implement pow(x, n), which calculates x raised to the power n (xn).
-
+Implement pow(x, n), which calculates x raised to the power n (xn).
Example 1:
-
-
Input: 2.00000, 10
@@ -19,12 +16,8 @@
-
-
Example 2:
-
-
Input: 2.10000, 3
@@ -33,12 +26,8 @@
-
-
Example 3:
-
-
Input: 2.00000, -2
@@ -49,26 +38,18 @@
-
-
Note:
-
-
- - -100.0 < x < 100.0
+ - -100.0 < x < 100.0
- - n is a 32-bit signed integer, within the range [−231, 231 − 1]
+ - n is a 32-bit signed integer, within the range [−231, 231 − 1]
-
-
-
## Solutions
-
### **Python3**
@@ -84,8 +65,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0050.Pow(x, n)/Solution.js b/solution/0000-0099/0050.Pow(x, n)/Solution.js
index 8dfd15f5a101a..8a4a7dad9a623 100644
--- a/solution/0000-0099/0050.Pow(x, n)/Solution.js
+++ b/solution/0000-0099/0050.Pow(x, n)/Solution.js
@@ -3,11 +3,13 @@
* @param {number} n
* @return {number}
*/
-var myPow = function(x, n) {
- if (n == 0) return 1
- if (n < 0) {
- n = -n
- x = 1 / x
- }
- return (n % 2 == 0) ? Math.pow(x * x, parseInt(n / 2)) : x*Math.pow(x * x, parseInt(n / 2));
- };
\ No newline at end of file
+var myPow = function (x, n) {
+ if (n == 0) return 1;
+ if (n < 0) {
+ n = -n;
+ x = 1 / x;
+ }
+ return n % 2 == 0
+ ? Math.pow(x * x, parseInt(n / 2))
+ : x * Math.pow(x * x, parseInt(n / 2));
+};
diff --git a/solution/0000-0099/0051.N-Queens/README.md b/solution/0000-0099/0051.N-Queens/README.md
index 9c8ac90b87d19..35e49cde6977c 100644
--- a/solution/0000-0099/0051.N-Queens/README.md
+++ b/solution/0000-0099/0051.N-Queens/README.md
@@ -1,8 +1,9 @@
-# [51. N皇后](https://leetcode-cn.com/problems/n-queens)
+# [51. N 皇后](https://leetcode-cn.com/problems/n-queens)
[English Version](/solution/0000-0099/0051.N-Queens/README_EN.md)
## 题目描述
+
n 皇后问题研究的是如何将 n 个皇后放置在 n×n 的棋盘上,并且使皇后彼此之间不能相互攻击。
@@ -31,15 +32,14 @@
解释: 4 皇后问题存在两个不同的解法。
-
-
## 解法
-
+
### **Python3**
+
```python
@@ -47,6 +47,7 @@
```
### **Java**
+
```java
@@ -54,8 +55,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0051.N-Queens/README_EN.md b/solution/0000-0099/0051.N-Queens/README_EN.md
index 2b6545167872c..93cd62a3534b0 100644
--- a/solution/0000-0099/0051.N-Queens/README_EN.md
+++ b/solution/0000-0099/0051.N-Queens/README_EN.md
@@ -3,23 +3,17 @@
[中文文档](/solution/0000-0099/0051.N-Queens/README.md)
## Description
-The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.
+The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.

Given an integer n, return all distinct solutions to the n-queens puzzle.
-
-
Each solution contains a distinct board configuration of the n-queens' placement, where 'Q'
and '.'
both indicate a queen and an empty space respectively.
-
-
Example:
-
-
Input: 4
@@ -50,12 +44,8 @@
-
-
-
## Solutions
-
### **Python3**
@@ -71,8 +61,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0052.N-Queens II/README.md b/solution/0000-0099/0052.N-Queens II/README.md
index b237301313608..57584917f32f6 100644
--- a/solution/0000-0099/0052.N-Queens II/README.md
+++ b/solution/0000-0099/0052.N-Queens II/README.md
@@ -1,8 +1,9 @@
-# [52. N皇后 II](https://leetcode-cn.com/problems/n-queens-ii)
+# [52. N 皇后 II](https://leetcode-cn.com/problems/n-queens-ii)
[English Version](/solution/0000-0099/0052.N-Queens%20II/README_EN.md)
## 题目描述
+
n 皇后问题研究的是如何将 n 个皇后放置在 n×n 的棋盘上,并且使皇后彼此之间不能相互攻击。
@@ -30,15 +31,14 @@
]
-
-
## 解法
-
+
### **Python3**
+
```python
@@ -46,6 +46,7 @@
```
### **Java**
+
```java
@@ -53,8 +54,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0052.N-Queens II/README_EN.md b/solution/0000-0099/0052.N-Queens II/README_EN.md
index ef71b3797df61..55ea9c2cf7dba 100644
--- a/solution/0000-0099/0052.N-Queens II/README_EN.md
+++ b/solution/0000-0099/0052.N-Queens II/README_EN.md
@@ -3,20 +3,15 @@
[中文文档](/solution/0000-0099/0052.N-Queens%20II/README.md)
## Description
-The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.
+The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.

-
Given an integer n, return the number of distinct solutions to the n-queens puzzle.
-
-
Example:
-
-
Input: 4
@@ -49,12 +44,8 @@
-
-
-
## Solutions
-
### **Python3**
@@ -70,8 +61,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0053.Maximum Subarray/README.md b/solution/0000-0099/0053.Maximum Subarray/README.md
index e9f9f33c1b5c5..c383361abc458 100644
--- a/solution/0000-0099/0053.Maximum Subarray/README.md
+++ b/solution/0000-0099/0053.Maximum Subarray/README.md
@@ -3,6 +3,7 @@
[English Version](/solution/0000-0099/0053.Maximum%20Subarray/README_EN.md)
## 题目描述
+
给定一个整数数组 nums
,找到一个具有最大和的连续子数组(子数组最少包含一个元素),返回其最大和。
@@ -17,15 +18,14 @@
如果你已经实现复杂度为 O(n) 的解法,尝试使用更为精妙的分治法求解。
-
-
## 解法
-
+
### **Python3**
+
```python
@@ -33,6 +33,7 @@
```
### **Java**
+
```java
@@ -40,8 +41,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0053.Maximum Subarray/README_EN.md b/solution/0000-0099/0053.Maximum Subarray/README_EN.md
index e89b3075e3c63..ed374a2ef4689 100644
--- a/solution/0000-0099/0053.Maximum Subarray/README_EN.md
+++ b/solution/0000-0099/0053.Maximum Subarray/README_EN.md
@@ -3,14 +3,11 @@
[中文文档](/solution/0000-0099/0053.Maximum%20Subarray/README.md)
## Description
-Given an integer array nums
, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum.
-
+Given an integer array nums
, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum.
Example:
-
-
Input: [-2,1,-3,4,-1,2,1,-5,4],
@@ -21,20 +18,12 @@
-
-
Follow up:
-
-
If you have figured out the O(n) solution, try coding another solution using the divide and conquer approach, which is more subtle.
-
-
-
## Solutions
-
### **Python3**
@@ -50,8 +39,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0053.Maximum Subarray/Solution.js b/solution/0000-0099/0053.Maximum Subarray/Solution.js
index 6964d3fb2ed0e..3225c46377fb8 100644
--- a/solution/0000-0099/0053.Maximum Subarray/Solution.js
+++ b/solution/0000-0099/0053.Maximum Subarray/Solution.js
@@ -1,9 +1,10 @@
-const maxSubArray = function(nums){
- if(nums.length === 0) return 0;
- let ans = nums[0], tmp = nums[0];
- for(let i = 1; i < nums.length; i++){
- tmp = Math.max(tmp+nums[i], nums[i]);
- ans = Math.max(ans,tmp);
+const maxSubArray = function (nums) {
+ if (nums.length === 0) return 0;
+ let ans = nums[0],
+ tmp = nums[0];
+ for (let i = 1; i < nums.length; i++) {
+ tmp = Math.max(tmp + nums[i], nums[i]);
+ ans = Math.max(ans, tmp);
}
return ans;
-}
\ No newline at end of file
+};
diff --git a/solution/0000-0099/0054.Spiral Matrix/README.md b/solution/0000-0099/0054.Spiral Matrix/README.md
index d419a3fe61ba3..008bfc95f7ce2 100644
--- a/solution/0000-0099/0054.Spiral Matrix/README.md
+++ b/solution/0000-0099/0054.Spiral Matrix/README.md
@@ -3,6 +3,7 @@
[English Version](/solution/0000-0099/0054.Spiral%20Matrix/README_EN.md)
## 题目描述
+
给定一个包含 m x n 个元素的矩阵(m 行, n 列),请按照顺时针螺旋顺序,返回矩阵中的所有元素。
@@ -28,15 +29,14 @@
输出: [1,2,3,4,8,12,11,10,9,5,6,7]
-
-
## 解法
-
+
### **Python3**
+
```python
@@ -44,6 +44,7 @@
```
### **Java**
+
```java
@@ -51,8 +52,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0054.Spiral Matrix/README_EN.md b/solution/0000-0099/0054.Spiral Matrix/README_EN.md
index 2cc73cc951287..29416c8eff675 100644
--- a/solution/0000-0099/0054.Spiral Matrix/README_EN.md
+++ b/solution/0000-0099/0054.Spiral Matrix/README_EN.md
@@ -3,14 +3,11 @@
[中文文档](/solution/0000-0099/0054.Spiral%20Matrix/README.md)
## Description
-Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.
-
+Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.
Example 1:
-
-
Input:
@@ -29,8 +26,6 @@
-
-
Example 2:
@@ -51,10 +46,8 @@
-
## Solutions
-
### **Python3**
@@ -70,8 +63,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0055.Jump Game/README.md b/solution/0000-0099/0055.Jump Game/README.md
index e7ce7b2ece159..b1f9ca406acf7 100644
--- a/solution/0000-0099/0055.Jump Game/README.md
+++ b/solution/0000-0099/0055.Jump Game/README.md
@@ -3,6 +3,7 @@
[English Version](/solution/0000-0099/0055.Jump%20Game/README_EN.md)
## 题目描述
+
给定一个非负整数数组,你最初位于数组的第一个位置。
@@ -24,15 +25,14 @@
解释: 无论怎样,你总会到达索引为 3 的位置。但该位置的最大跳跃长度是 0 , 所以你永远不可能到达最后一个位置。
-
-
## 解法
-
+
### **Python3**
+
```python
@@ -40,6 +40,7 @@
```
### **Java**
+
```java
@@ -47,8 +48,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0055.Jump Game/README_EN.md b/solution/0000-0099/0055.Jump Game/README_EN.md
index b99e54a70e568..1ff3569b54eb7 100644
--- a/solution/0000-0099/0055.Jump Game/README_EN.md
+++ b/solution/0000-0099/0055.Jump Game/README_EN.md
@@ -3,22 +3,15 @@
[中文文档](/solution/0000-0099/0055.Jump%20Game/README.md)
## Description
-Given an array of non-negative integers, you are initially positioned at the first index of the array.
-
+Given an array of non-negative integers, you are initially positioned at the first index of the array.
Each element in the array represents your maximum jump length at that position.
-
-
Determine if you are able to reach the last index.
-
-
Example 1:
-
-
Input: [2,3,1,1,4]
@@ -29,12 +22,8 @@
-
-
Example 2:
-
-
Input: [3,2,1,0,4]
@@ -47,12 +36,8 @@
-
-
-
## Solutions
-
### **Python3**
@@ -68,8 +53,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0056.Merge Intervals/README.md b/solution/0000-0099/0056.Merge Intervals/README.md
index 0f0b4a470728c..a92991de167be 100644
--- a/solution/0000-0099/0056.Merge Intervals/README.md
+++ b/solution/0000-0099/0056.Merge Intervals/README.md
@@ -3,6 +3,7 @@
[English Version](/solution/0000-0099/0056.Merge%20Intervals/README_EN.md)
## 题目描述
+
给出一个区间的集合,请合并所有重叠的区间。
@@ -19,15 +20,14 @@
输出: [[1,5]]
解释: 区间 [1,4] 和 [4,5] 可被视为重叠区间。
-
-
## 解法
-
+
### **Python3**
+
```python
@@ -35,6 +35,7 @@
```
### **Java**
+
```java
@@ -42,8 +43,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0056.Merge Intervals/README_EN.md b/solution/0000-0099/0056.Merge Intervals/README_EN.md
index 1ed2bd586903f..a623ce4406d89 100644
--- a/solution/0000-0099/0056.Merge Intervals/README_EN.md
+++ b/solution/0000-0099/0056.Merge Intervals/README_EN.md
@@ -3,14 +3,11 @@
[中文文档](/solution/0000-0099/0056.Merge%20Intervals/README.md)
## Description
-Given a collection of intervals, merge all overlapping intervals.
-
+Given a collection of intervals, merge all overlapping intervals.
Example 1:
-
-
Input: [[1,3],[2,6],[8,10],[15,18]]
@@ -21,12 +18,8 @@
-
-
Example 2:
-
-
Input: [[1,4],[4,5]]
@@ -35,16 +28,10 @@
Explanation: Intervals [1,4] and [4,5] are considered overlapping.
-
-
NOTE: input types have been changed on April 15, 2019. Please reset to default code definition to get new method signature.
-
-
-
## Solutions
-
### **Python3**
@@ -60,8 +47,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0057.Insert Interval/README.md b/solution/0000-0099/0057.Insert Interval/README.md
index 12434a145fd6e..f086e12f11c86 100644
--- a/solution/0000-0099/0057.Insert Interval/README.md
+++ b/solution/0000-0099/0057.Insert Interval/README.md
@@ -3,6 +3,7 @@
[English Version](/solution/0000-0099/0057.Insert%20Interval/README_EN.md)
## 题目描述
+
给出一个无重叠的 ,按照区间起始端点排序的区间列表。
@@ -21,15 +22,14 @@
解释: 这是因为新的区间 [4,8]
与 [3,5],[6,7],[8,10]
重叠。
-
-
## 解法
-
+
### **Python3**
+
```python
@@ -37,6 +37,7 @@
```
### **Java**
+
```java
@@ -44,8 +45,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0057.Insert Interval/README_EN.md b/solution/0000-0099/0057.Insert Interval/README_EN.md
index 1cf7726c77fb5..8c90b2afcc578 100644
--- a/solution/0000-0099/0057.Insert Interval/README_EN.md
+++ b/solution/0000-0099/0057.Insert Interval/README_EN.md
@@ -3,18 +3,13 @@
[中文文档](/solution/0000-0099/0057.Insert%20Interval/README.md)
## Description
-Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary).
-
+Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary).
You may assume that the intervals were initially sorted according to their start times.
-
-
Example 1:
-
-
Input: intervals = [[1,3],[6,9]], newInterval = [2,5]
@@ -23,12 +18,8 @@
-
-
Example 2:
-
-
Input: intervals = [[1,2],[3,5],[6,7],[8,10],[12,16]]
, newInterval = [4,8]
@@ -37,16 +28,10 @@
Explanation: Because the new interval [4,8]
overlaps with [3,5],[6,7],[8,10]
.
-
-
NOTE: input types have been changed on April 15, 2019. Please reset to default code definition to get new method signature.
-
-
-
## Solutions
-
### **Python3**
@@ -62,8 +47,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0058.Length of Last Word/README.md b/solution/0000-0099/0058.Length of Last Word/README.md
index 4146e8271670f..812d6054eeef9 100644
--- a/solution/0000-0099/0058.Length of Last Word/README.md
+++ b/solution/0000-0099/0058.Length of Last Word/README.md
@@ -3,6 +3,7 @@
[English Version](/solution/0000-0099/0058.Length%20of%20Last%20Word/README_EN.md)
## 题目描述
+
给定一个仅包含大小写字母和空格 ' '
的字符串 s
,返回其最后一个单词的长度。如果字符串从左向右滚动显示,那么最后一个单词就是最后出现的单词。
@@ -18,15 +19,14 @@
输出: 5
-
-
## 解法
-
+
### **Python3**
+
```python
@@ -34,6 +34,7 @@
```
### **Java**
+
```java
@@ -41,8 +42,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0058.Length of Last Word/README_EN.md b/solution/0000-0099/0058.Length of Last Word/README_EN.md
index fe9a9d1c35b4c..d894f5488f378 100644
--- a/solution/0000-0099/0058.Length of Last Word/README_EN.md
+++ b/solution/0000-0099/0058.Length of Last Word/README_EN.md
@@ -3,6 +3,7 @@
[中文文档](/solution/0000-0099/0058.Length%20of%20Last%20Word/README.md)
## Description
+
Given a string s consists of upper/lower-case alphabets and empty space characters ' '
, return the length of last word (last word means the last appearing word if we loop from left to right) in the string.
If the last word does not exist, return 0.
@@ -18,11 +19,8 @@
-
-
## Solutions
-
### **Python3**
@@ -38,8 +36,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0058.Length of Last Word/Solution.js b/solution/0000-0099/0058.Length of Last Word/Solution.js
index a8d00bc3f916e..348d2344d0815 100644
--- a/solution/0000-0099/0058.Length of Last Word/Solution.js
+++ b/solution/0000-0099/0058.Length of Last Word/Solution.js
@@ -1,16 +1,16 @@
var lengthOfLastWord = function (s) {
- s = s.trim()
- return s.length - s.lastIndexOf(" ") - 1
+ s = s.trim();
+ return s.length - s.lastIndexOf(" ") - 1;
};
var lengthOfLastWord2 = function (s) {
- let res = 0
+ let res = 0;
for (let i = 0; i < s.length; i++) {
- if (s[i] !== ' ' && (i === 0 || s[i - 1] === ' ')) {
- res = 1
- } else if (s[i] !== ' ') {
- res++
+ if (s[i] !== " " && (i === 0 || s[i - 1] === " ")) {
+ res = 1;
+ } else if (s[i] !== " ") {
+ res++;
}
}
- return res
-}
\ No newline at end of file
+ return res;
+};
diff --git a/solution/0000-0099/0059.Spiral Matrix II/README.md b/solution/0000-0099/0059.Spiral Matrix II/README.md
index c04d4f1e9ea9d..87309a97c28ec 100644
--- a/solution/0000-0099/0059.Spiral Matrix II/README.md
+++ b/solution/0000-0099/0059.Spiral Matrix II/README.md
@@ -3,6 +3,7 @@
[English Version](/solution/0000-0099/0059.Spiral%20Matrix%20II/README_EN.md)
## 题目描述
+
给定一个正整数 n,生成一个包含 1 到 n2 所有元素,且元素按顺时针顺序螺旋排列的正方形矩阵。
@@ -16,15 +17,14 @@
[ 7, 6, 5 ]
]
-
-
## 解法
-
+
### **Python3**
+
```python
@@ -32,6 +32,7 @@
```
### **Java**
+
```java
@@ -39,8 +40,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0059.Spiral Matrix II/README_EN.md b/solution/0000-0099/0059.Spiral Matrix II/README_EN.md
index ac1d845a0448f..d14804ab5a3e5 100644
--- a/solution/0000-0099/0059.Spiral Matrix II/README_EN.md
+++ b/solution/0000-0099/0059.Spiral Matrix II/README_EN.md
@@ -3,14 +3,11 @@
[中文文档](/solution/0000-0099/0059.Spiral%20Matrix%20II/README.md)
## Description
-Given a positive integer n, generate a square matrix filled with elements from 1 to n2 in spiral order.
-
+Given a positive integer n, generate a square matrix filled with elements from 1 to n2 in spiral order.
Example:
-
-
Input: 3
@@ -29,12 +26,8 @@
-
-
-
## Solutions
-
### **Python3**
@@ -50,8 +43,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0060.Permutation Sequence/README.md b/solution/0000-0099/0060.Permutation Sequence/README.md
index b8b14e5709449..a15e2e70c3e72 100644
--- a/solution/0000-0099/0060.Permutation Sequence/README.md
+++ b/solution/0000-0099/0060.Permutation Sequence/README.md
@@ -1,8 +1,9 @@
-# [60. 第k个排列](https://leetcode-cn.com/problems/permutation-sequence)
+# [60. 第 k 个排列](https://leetcode-cn.com/problems/permutation-sequence)
[English Version](/solution/0000-0099/0060.Permutation%20Sequence/README_EN.md)
## 题目描述
+
给出集合 [1,2,3,…,n]
,其所有元素共有 n! 种排列。
@@ -38,15 +39,14 @@
输出: "2314"
-
-
## 解法
-
+
### **Python3**
+
```python
@@ -54,6 +54,7 @@
```
### **Java**
+
```java
@@ -61,8 +62,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0060.Permutation Sequence/README_EN.md b/solution/0000-0099/0060.Permutation Sequence/README_EN.md
index b66fbc1e2eb70..41b96d73e3819 100644
--- a/solution/0000-0099/0060.Permutation Sequence/README_EN.md
+++ b/solution/0000-0099/0060.Permutation Sequence/README_EN.md
@@ -3,54 +3,41 @@
[中文文档](/solution/0000-0099/0060.Permutation%20Sequence/README.md)
## Description
-The set [1,2,3,...,n]
contains a total of n! unique permutations.
-
+The set [1,2,3,...,n]
contains a total of n! unique permutations.
By listing and labeling all of the permutations in order, we get the following sequence for n = 3:
-
-
- "123"
+ "123"
- "132"
+ "132"
- "213"
+ "213"
- "231"
+ "231"
- "312"
+ "312"
- "321"
+ "321"
-
-
Given n and k, return the kth permutation sequence.
-
-
Note:
-
-
- - Given n will be between 1 and 9 inclusive.
+ - Given n will be between 1 and 9 inclusive.
- - Given k will be between 1 and n! inclusive.
+ - Given k will be between 1 and n! inclusive.
-
-
Example 1:
-
-
Input: n = 3, k = 3
@@ -59,12 +46,8 @@
-
-
Example 2:
-
-
Input: n = 4, k = 9
@@ -73,12 +56,8 @@
-
-
-
## Solutions
-
### **Python3**
@@ -94,8 +73,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0061.Rotate List/README.md b/solution/0000-0099/0061.Rotate List/README.md
index fbce1fcd8a4eb..62847f97dfb2d 100644
--- a/solution/0000-0099/0061.Rotate List/README.md
+++ b/solution/0000-0099/0061.Rotate List/README.md
@@ -3,6 +3,7 @@
[English Version](/solution/0000-0099/0061.Rotate%20List/README_EN.md)
## 题目描述
+
给定一个链表,旋转链表,将链表每个节点向右移动 k 个位置,其中 k 是非负数。
@@ -25,15 +26,14 @@
向右旋转 3 步: 0->1->2->NULL
向右旋转 4 步: 2->0->1->NULL
-
-
## 解法
-
+
### **Python3**
+
```python
@@ -41,6 +41,7 @@
```
### **Java**
+
```java
@@ -48,8 +49,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0061.Rotate List/README_EN.md b/solution/0000-0099/0061.Rotate List/README_EN.md
index 5a866849a7979..b9eeddf8fe3f7 100644
--- a/solution/0000-0099/0061.Rotate List/README_EN.md
+++ b/solution/0000-0099/0061.Rotate List/README_EN.md
@@ -3,14 +3,11 @@
[中文文档](/solution/0000-0099/0061.Rotate%20List/README.md)
## Description
-Given a linked list, rotate the list to the right by k places, where k is non-negative.
-
+Given a linked list, rotate the list to the right by k places, where k is non-negative.
Example 1:
-
-
Input: 1->2->3->4->5->NULL, k = 2
@@ -25,12 +22,8 @@ rotate 2 steps to the right: 4->5->1->2->3->NULL
-
-
Example 2:
-
-
Input: 0->1->2->NULL, k = 4
@@ -47,12 +40,8 @@ rotate 3 steps to the right: 0->1->2->NULL
rotate 4 steps to the right: 2->0->1->NULL
-
-
-
## Solutions
-
### **Python3**
@@ -68,8 +57,9 @@ rotate 4 steps to the right: 2->0->1->NULL
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0062.Unique Paths/README.md b/solution/0000-0099/0062.Unique Paths/README.md
index 0048c57017d14..6c82a0e4bef74 100644
--- a/solution/0000-0099/0062.Unique Paths/README.md
+++ b/solution/0000-0099/0062.Unique Paths/README.md
@@ -3,6 +3,7 @@
[English Version](/solution/0000-0099/0062.Unique%20Paths/README_EN.md)
## 题目描述
+
一个机器人位于一个 m x n 网格的左上角 (起始点在下图中标记为“Start” )。
@@ -41,15 +42,14 @@
题目数据保证答案小于等于 2 * 10 ^ 9
-
-
## 解法
-
+
### **Python3**
+
```python
@@ -57,6 +57,7 @@
```
### **Java**
+
```java
@@ -64,8 +65,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0062.Unique Paths/README_EN.md b/solution/0000-0099/0062.Unique Paths/README_EN.md
index a2ff7d3348d6f..77e40266be745 100644
--- a/solution/0000-0099/0062.Unique Paths/README_EN.md
+++ b/solution/0000-0099/0062.Unique Paths/README_EN.md
@@ -3,6 +3,7 @@
[中文文档](/solution/0000-0099/0062.Unique%20Paths/README.md)
## Description
+
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 bottom-right corner of the grid (marked 'Finish' in the diagram below).
@@ -41,11 +42,8 @@ From the top-left corner, there are a total of 3 ways to reach the bottom-right
It's guaranteed that the answer will be less than or equal to 2 * 10 ^ 9
.
-
-
## Solutions
-
### **Python3**
@@ -61,8 +59,9 @@ From the top-left corner, there are a total of 3 ways to reach the bottom-right
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0063.Unique Paths II/README.md b/solution/0000-0099/0063.Unique Paths II/README.md
index 32611688892eb..a99d9c6591c5a 100644
--- a/solution/0000-0099/0063.Unique Paths II/README.md
+++ b/solution/0000-0099/0063.Unique Paths II/README.md
@@ -3,6 +3,7 @@
[English Version](/solution/0000-0099/0063.Unique%20Paths%20II/README_EN.md)
## 题目描述
+
一个机器人位于一个 m x n 网格的左上角 (起始点在下图中标记为“Start” )。
@@ -32,13 +33,13 @@
2. 向下 -> 向下 -> 向右 -> 向右
-
-
## 解法
+
### **Go**
-``` go
+
+````go
func uniquePathsWithObstacles(obstacleGrid [][]int) int {
m,n := len(obstacleGrid),len(obstacleGrid[0])
dp := make([][]int,m)
@@ -58,7 +59,7 @@ func uniquePathsWithObstacles(obstacleGrid [][]int) int {
dp[i][j] = dp[i][j-1]
}
}
- }
+ }
}
return dp[m-1][n-1]
}
@@ -71,9 +72,10 @@ func uniquePathsWithObstacles(obstacleGrid [][]int) int {
```python
-```
+````
### **Java**
+
```java
@@ -81,8 +83,9 @@ func uniquePathsWithObstacles(obstacleGrid [][]int) int {
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0063.Unique Paths II/README_EN.md b/solution/0000-0099/0063.Unique Paths II/README_EN.md
index 325173fe7c16e..91fd5c0e828eb 100644
--- a/solution/0000-0099/0063.Unique Paths II/README_EN.md
+++ b/solution/0000-0099/0063.Unique Paths II/README_EN.md
@@ -1,108 +1,99 @@
-# [63. Unique Paths II](https://leetcode.com/problems/unique-paths-ii)
-
-[中文文档](/solution/0000-0099/0063.Unique%20Paths%20II/README.md)
-
-## Description
-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 bottom-right corner of the grid (marked 'Finish' in the diagram below).
-
-
-
-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
respectively in the grid.
-
-
-
-Note: m and n will be at most 100.
-
-
-
-Example 1:
-
-
-
-
-
-Input:
-
-[
-
- [0,0,0],
-
- [0,1,0],
-
- [0,0,0]
-
-]
-
-Output: 2
-
-Explanation:
-
-There is one obstacle in the middle of the 3x3 grid above.
-
-There are two ways to reach the bottom-right corner:
-
-1. Right -> Right -> Down -> Down
-
-2. Down -> Down -> Right -> Right
-
-
-
-
-
-
-## Solutions
-
-### **Go**
-```go
-func uniquePathsWithObstacles(obstacleGrid [][]int) int {
- m,n := len(obstacleGrid),len(obstacleGrid[0])
- dp := make([][]int,m)
- for i:=0; i < m;i++ {
- dp[i] = make([]int,n)
- }
- for i := 0; i < m; i++ {
- for j := 0; j < n; j++ {
- if obstacleGrid[i][j] == 0 {
- if i == 0 && j == 0 {
- dp[i][j] = 1
- } else if i > 0 && j >0 {
- dp[i][j] = dp[i][j-1]+dp[i-1][j]
- } else if i > 0 {
- dp[i][j] = dp[i-1][j]
- } else {
- dp[i][j] = dp[i][j-1]
- }
- }
- }
- }
- return dp[m-1][n-1]
-}
-```
-
-
-### **Python3**
-
-```python
-
-```
-
-### **Java**
-
-```java
-
-```
-
-### **...**
-```
-
-```
-
-
\ No newline at end of file
+# [63. Unique Paths II](https://leetcode.com/problems/unique-paths-ii)
+
+[中文文档](/solution/0000-0099/0063.Unique%20Paths%20II/README.md)
+
+## Description
+
+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 bottom-right corner of the grid (marked 'Finish' in the diagram below).
+
+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
respectively in the grid.
+
+Note: m and n will be at most 100.
+
+Example 1:
+
+
+
+Input:
+
+[
+
+ [0,0,0],
+
+ [0,1,0],
+
+ [0,0,0]
+
+]
+
+Output: 2
+
+Explanation:
+
+There is one obstacle in the middle of the 3x3 grid above.
+
+There are two ways to reach the bottom-right corner:
+
+1. Right -> Right -> Down -> Down
+
+2. Down -> Down -> Right -> Right
+
+
+
+## Solutions
+
+### **Go**
+
+```go
+func uniquePathsWithObstacles(obstacleGrid [][]int) int {
+ m,n := len(obstacleGrid),len(obstacleGrid[0])
+ dp := make([][]int,m)
+ for i:=0; i < m;i++ {
+ dp[i] = make([]int,n)
+ }
+ for i := 0; i < m; i++ {
+ for j := 0; j < n; j++ {
+ if obstacleGrid[i][j] == 0 {
+ if i == 0 && j == 0 {
+ dp[i][j] = 1
+ } else if i > 0 && j >0 {
+ dp[i][j] = dp[i][j-1]+dp[i-1][j]
+ } else if i > 0 {
+ dp[i][j] = dp[i-1][j]
+ } else {
+ dp[i][j] = dp[i][j-1]
+ }
+ }
+ }
+ }
+ return dp[m-1][n-1]
+}
+```
+
+
+
+### **Python3**
+
+```python
+
+```
+
+### **Java**
+
+```java
+
+```
+
+### **...**
+
+```
+
+```
+
+
diff --git a/solution/0000-0099/0064.Minimum Path Sum/README.md b/solution/0000-0099/0064.Minimum Path Sum/README.md
index d82c2863642e6..23e370cdc62b2 100644
--- a/solution/0000-0099/0064.Minimum Path Sum/README.md
+++ b/solution/0000-0099/0064.Minimum Path Sum/README.md
@@ -3,6 +3,7 @@
[English Version](/solution/0000-0099/0064.Minimum%20Path%20Sum/README_EN.md)
## 题目描述
+
给定一个包含非负整数的 m x n 网格,请找出一条从左上角到右下角的路径,使得路径上的数字总和为最小。
@@ -20,15 +21,14 @@
解释: 因为路径 1→3→1→1→1 的总和最小。
-
-
## 解法
-
+
### **Python3**
+
```python
@@ -36,6 +36,7 @@
```
### **Java**
+
```java
@@ -43,8 +44,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0064.Minimum Path Sum/README_EN.md b/solution/0000-0099/0064.Minimum Path Sum/README_EN.md
index b460ff518ba3c..5bc409fd38007 100644
--- a/solution/0000-0099/0064.Minimum Path Sum/README_EN.md
+++ b/solution/0000-0099/0064.Minimum Path Sum/README_EN.md
@@ -3,18 +3,13 @@
[中文文档](/solution/0000-0099/0064.Minimum%20Path%20Sum/README.md)
## Description
-Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path.
-
+Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path.
Note: You can only move either down or right at any point in time.
-
-
Example:
-
-
Input:
@@ -35,12 +30,8 @@
-
-
-
## Solutions
-
### **Python3**
@@ -56,8 +47,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0065.Valid Number/README.md b/solution/0000-0099/0065.Valid Number/README.md
index e26f8a48722df..ab31fbb32e221 100644
--- a/solution/0000-0099/0065.Valid Number/README.md
+++ b/solution/0000-0099/0065.Valid Number/README.md
@@ -3,6 +3,7 @@
[English Version](/solution/0000-0099/0065.Valid%20Number/README_EN.md)
## 题目描述
+
验证给定的字符串是否可以解释为十进制数字。
@@ -37,15 +38,14 @@
更新于 2015-02-10:
C++
函数的形式已经更新了。如果你仍然看见你的函数接收 const char *
类型的参数,请点击重载按钮重置你的代码。
-
-
## 解法
-
+
### **Python3**
+
```python
@@ -53,6 +53,7 @@
```
### **Java**
+
```java
@@ -60,8 +61,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0065.Valid Number/README_EN.md b/solution/0000-0099/0065.Valid Number/README_EN.md
index c8bb604a3da68..83c028ecc4f42 100644
--- a/solution/0000-0099/0065.Valid Number/README_EN.md
+++ b/solution/0000-0099/0065.Valid Number/README_EN.md
@@ -3,9 +3,8 @@
[中文文档](/solution/0000-0099/0065.Valid%20Number/README.md)
## Description
-Validate if a given string can be interpreted as a decimal number.
-
+Validate if a given string can be interpreted as a decimal number.
Some examples:
@@ -37,40 +36,28 @@
"95a54e53"
=> false
-
-
Note: It is intended for the problem statement to be ambiguous. You should gather all requirements up front before implementing one. However, here is a list of characters that can be in a valid decimal number:
-
-
- - Numbers 0-9
+ - Numbers 0-9
- - Exponent - "e"
+ - Exponent - "e"
- - Positive/negative sign - "+"/"-"
+ - Positive/negative sign - "+"/"-"
- - Decimal point - "."
+ - Decimal point - "."
-
-
Of course, the context of these characters also matters in the input.
-
-
Update (2015-02-10):
-The signature of the C++
function had been updated. If you still see your function signature accepts a const char *
argument, please click the reload button to reset your code definition.
-
-
-
+The signature of the C++
function had been updated. If you still see your function signature accepts a const char \*
argument, please click the reload button to reset your code definition.
## Solutions
-
### **Python3**
@@ -86,8 +73,9 @@ The signature of the C++
function had been updated. If you still se
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0066.Plus One/README.md b/solution/0000-0099/0066.Plus One/README.md
index fd2d027cc8f17..187c4d3da2d7e 100644
--- a/solution/0000-0099/0066.Plus One/README.md
+++ b/solution/0000-0099/0066.Plus One/README.md
@@ -3,6 +3,7 @@
[English Version](/solution/0000-0099/0066.Plus%20One/README_EN.md)
## 题目描述
+
给定一个由整数组成的非空数组所表示的非负整数,在该数的基础上加一。
@@ -24,15 +25,14 @@
解释: 输入数组表示数字 4321。
-
-
## 解法
-
+
### **Python3**
+
```python
@@ -40,6 +40,7 @@
```
### **Java**
+
```java
@@ -47,8 +48,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0066.Plus One/README_EN.md b/solution/0000-0099/0066.Plus One/README_EN.md
index c9680af5cca03..69f4587c9cbda 100644
--- a/solution/0000-0099/0066.Plus One/README_EN.md
+++ b/solution/0000-0099/0066.Plus One/README_EN.md
@@ -3,22 +3,15 @@
[中文文档](/solution/0000-0099/0066.Plus%20One/README.md)
## Description
-Given a non-empty array of digits representing a non-negative integer, plus one to the integer.
-
+Given a non-empty array of digits representing a non-negative integer, plus one to the integer.
The digits are stored such that the most significant digit is at the head of the list, and each element in the array contain a single digit.
-
-
You may assume the integer does not contain any leading zero, except the number 0 itself.
-
-
Example 1:
-
-
Input: [1,2,3]
@@ -29,12 +22,8 @@
-
-
Example 2:
-
-
Input: [4,3,2,1]
@@ -45,10 +34,8 @@
-
## Solutions
-
### **Python3**
@@ -64,8 +51,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0066.Plus One/Solution.js b/solution/0000-0099/0066.Plus One/Solution.js
index 47adcb87ca3b0..f72bcc367c917 100644
--- a/solution/0000-0099/0066.Plus One/Solution.js
+++ b/solution/0000-0099/0066.Plus One/Solution.js
@@ -1,12 +1,12 @@
-const plusOne = function(digits){
- for(let i = digits.length - 1; i >= 0; i--){
- if(digits[i] === 9){
+const plusOne = function (digits) {
+ for (let i = digits.length - 1; i >= 0; i--) {
+ if (digits[i] === 9) {
digits[i] = 0;
- }else{
+ } else {
digits[i] += 1;
return digits;
}
}
digits.unshift(1);
return digits;
-};
\ No newline at end of file
+};
diff --git a/solution/0000-0099/0067.Add Binary/README.md b/solution/0000-0099/0067.Add Binary/README.md
index acd15bbb581ad..ac6bdbabb9789 100644
--- a/solution/0000-0099/0067.Add Binary/README.md
+++ b/solution/0000-0099/0067.Add Binary/README.md
@@ -3,6 +3,7 @@
[English Version](/solution/0000-0099/0067.Add%20Binary/README_EN.md)
## 题目描述
+
给定两个二进制字符串,返回他们的和(用二进制表示)。
@@ -18,15 +19,14 @@
输入: a = "1010", b = "1011"
输出: "10101"
-
-
## 解法
-
+
### **Python3**
+
```python
@@ -34,6 +34,7 @@
```
### **Java**
+
```java
@@ -41,8 +42,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0067.Add Binary/README_EN.md b/solution/0000-0099/0067.Add Binary/README_EN.md
index eb46de91f178d..55da79171e77a 100644
--- a/solution/0000-0099/0067.Add Binary/README_EN.md
+++ b/solution/0000-0099/0067.Add Binary/README_EN.md
@@ -3,42 +3,29 @@
[中文文档](/solution/0000-0099/0067.Add%20Binary/README.md)
## Description
-Given two binary strings, return their sum (also a binary string).
-
+Given two binary strings, return their sum (also a binary string).
The input strings are both non-empty and contains only characters 1
or 0
.
-
-
Example 1:
-
-
Input: a = "11", b = "1"
Output: "100"
-
-
Example 2:
-
-
Input: a = "1010", b = "1011"
Output: "10101"
-
-
-
## Solutions
-
### **Python3**
@@ -54,8 +41,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0068.Text Justification/README.md b/solution/0000-0099/0068.Text Justification/README.md
index e4ff717096cc1..d7201c629d18e 100644
--- a/solution/0000-0099/0068.Text Justification/README.md
+++ b/solution/0000-0099/0068.Text Justification/README.md
@@ -3,6 +3,7 @@
[English Version](/solution/0000-0099/0068.Text%20Justification/README_EN.md)
## 题目描述
+
给定一个单词数组和一个长度 maxWidth,重新排版单词,使其成为每行恰好有 maxWidth 个字符,且左右两端对齐的文本。
@@ -66,15 +67,14 @@ maxWidth = 20
]
-
-
## 解法
-
+
### **Python3**
+
```python
@@ -82,6 +82,7 @@ maxWidth = 20
```
### **Java**
+
```java
@@ -89,8 +90,9 @@ maxWidth = 20
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0068.Text Justification/README_EN.md b/solution/0000-0099/0068.Text Justification/README_EN.md
index 58169dad6c7ce..c2ab75e2fe6bf 100644
--- a/solution/0000-0099/0068.Text Justification/README_EN.md
+++ b/solution/0000-0099/0068.Text Justification/README_EN.md
@@ -3,42 +3,29 @@
[中文文档](/solution/0000-0099/0068.Text%20Justification/README.md)
## Description
-Given an array of words and a width maxWidth, format the text such that each line has exactly maxWidth characters and is fully (left and right) justified.
-
+Given an array of words and a width maxWidth, format the text such that each line has exactly maxWidth characters and is fully (left and right) justified.
You should pack your words in a greedy approach; that is, pack as many words as you can in each line. Pad extra spaces ' '
when necessary so that each line has exactly maxWidth characters.
-
-
Extra spaces between words should be distributed as evenly as possible. If the number of spaces on a line do not divide evenly between words, the empty slots on the left will be assigned more spaces than the slots on the right.
-
-
For the last line of text, it should be left justified and no extra space is inserted between words.
-
-
Note:
-
-
- - A word is defined as a character sequence consisting of non-space characters only.
+ - A word is defined as a character sequence consisting of non-space characters only.
- - Each word's length is guaranteed to be greater than 0 and not exceed maxWidth.
+ - Each word's length is guaranteed to be greater than 0 and not exceed maxWidth.
- - The input array
words
contains at least one word.
+ - The input array
words
contains at least one word.
-
-
Example 1:
-
-
Input:
@@ -61,12 +48,8 @@ maxWidth = 16
-
-
Example 2:
-
-
Input:
@@ -95,12 +78,8 @@ maxWidth = 16
-
-
Example 3:
-
-
Input:
@@ -131,12 +110,8 @@ maxWidth = 20
-
-
-
## Solutions
-
### **Python3**
@@ -152,8 +127,9 @@ maxWidth = 20
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0069.Sqrt(x)/README.md b/solution/0000-0099/0069.Sqrt(x)/README.md
index ea68cc1159f92..cfe64205d6ba2 100644
--- a/solution/0000-0099/0069.Sqrt(x)/README.md
+++ b/solution/0000-0099/0069.Sqrt(x)/README.md
@@ -1,8 +1,9 @@
# [69. x 的平方根](https://leetcode-cn.com/problems/sqrtx)
-[English Version](/solution/0000-0099/0069.Sqrt(x)/README_EN.md)
+[English Version]()
## 题目描述
+
实现 int sqrt(int x)
函数。
@@ -24,15 +25,14 @@
由于返回类型是整数,小数部分将被舍去。
-
-
## 解法
-
+
### **Python3**
+
```python
@@ -40,6 +40,7 @@
```
### **Java**
+
```java
@@ -47,8 +48,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0069.Sqrt(x)/README_EN.md b/solution/0000-0099/0069.Sqrt(x)/README_EN.md
index c4f519b69c9ae..eccd64854e912 100644
--- a/solution/0000-0099/0069.Sqrt(x)/README_EN.md
+++ b/solution/0000-0099/0069.Sqrt(x)/README_EN.md
@@ -1,24 +1,17 @@
# [69. Sqrt(x)](https://leetcode.com/problems/sqrtx)
-[中文文档](/solution/0000-0099/0069.Sqrt(x)/README.md)
+[中文文档]()
## Description
-Implement int sqrt(int x)
.
-
+Implement int sqrt(int x)
.
Compute and return the square root of x, where x is guaranteed to be a non-negative integer.
-
-
Since the return type is an integer, the decimal digits are truncated and only the integer part of the result is returned.
-
-
Example 1:
-
-
Input: 4
@@ -27,12 +20,8 @@
-
-
Example 2:
-
-
Input: 8
@@ -45,12 +34,8 @@
-
-
-
## Solutions
-
### **Python3**
@@ -66,8 +51,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0069.Sqrt(x)/Solution.js b/solution/0000-0099/0069.Sqrt(x)/Solution.js
index 49c3dd5eeb1a5..5b243199c9cb7 100644
--- a/solution/0000-0099/0069.Sqrt(x)/Solution.js
+++ b/solution/0000-0099/0069.Sqrt(x)/Solution.js
@@ -2,17 +2,17 @@
* @param {number} x
* @return {number}
*/
-var mySqrt = function(x) {
- var left = 1
- var right = x
- var middle = Math.floor((left + right) / 2)
- while( middle !== left ) {
- if (middle * middle <= x) {
- left = middle
- } else {
- right = middle
- }
- middle = Math.floor((left + right) / 2)
- }
- return middle
+var mySqrt = function (x) {
+ var left = 1;
+ var right = x;
+ var middle = Math.floor((left + right) / 2);
+ while (middle !== left) {
+ if (middle * middle <= x) {
+ left = middle;
+ } else {
+ right = middle;
+ }
+ middle = Math.floor((left + right) / 2);
+ }
+ return middle;
};
diff --git a/solution/0000-0099/0070.Climbing Stairs/README.md b/solution/0000-0099/0070.Climbing Stairs/README.md
index 168f553040a07..a27bda8cd6bcd 100644
--- a/solution/0000-0099/0070.Climbing Stairs/README.md
+++ b/solution/0000-0099/0070.Climbing Stairs/README.md
@@ -3,6 +3,7 @@
[English Version](/solution/0000-0099/0070.Climbing%20Stairs/README_EN.md)
## 题目描述
+
假设你正在爬楼梯。需要 n 阶你才能到达楼顶。
@@ -28,15 +29,14 @@
3. 2 阶 + 1 阶
-
-
## 解法
-
+
### **Python3**
+
```python
@@ -44,6 +44,7 @@
```
### **Java**
+
```java
@@ -51,8 +52,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0070.Climbing Stairs/README_EN.md b/solution/0000-0099/0070.Climbing Stairs/README_EN.md
index 27d6086e33808..be2b26aab794c 100644
--- a/solution/0000-0099/0070.Climbing Stairs/README_EN.md
+++ b/solution/0000-0099/0070.Climbing Stairs/README_EN.md
@@ -3,22 +3,15 @@
[中文文档](/solution/0000-0099/0070.Climbing%20Stairs/README.md)
## Description
-You are climbing a stair case. It takes n steps to reach to the top.
-
+You are climbing a stair case. It takes n steps to reach to the top.
Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?
-
-
Note: Given n will be a positive integer.
-
-
Example 1:
-
-
Input: 2
@@ -33,12 +26,8 @@
-
-
Example 2:
-
-
Input: 3
@@ -55,12 +44,8 @@
-
-
-
## Solutions
-
### **Python3**
@@ -76,8 +61,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0070.Climbing Stairs/Solution.js b/solution/0000-0099/0070.Climbing Stairs/Solution.js
index 15d734536306c..92e09da26613b 100644
--- a/solution/0000-0099/0070.Climbing Stairs/Solution.js
+++ b/solution/0000-0099/0070.Climbing Stairs/Solution.js
@@ -1,9 +1,9 @@
-const climbStairs = function(n){
+const climbStairs = function (n) {
let arr = [];
arr[0] = 1;
arr[1] = 1;
- for(let i = 2; i <= n; i++){
- arr[i] = arr[i-1]+arr[i-2];
+ for (let i = 2; i <= n; i++) {
+ arr[i] = arr[i - 1] + arr[i - 2];
}
return arr[n];
-};
\ No newline at end of file
+};
diff --git a/solution/0000-0099/0071.Simplify Path/README.md b/solution/0000-0099/0071.Simplify Path/README.md
index 9176087118238..ea8d13de0e139 100644
--- a/solution/0000-0099/0071.Simplify Path/README.md
+++ b/solution/0000-0099/0071.Simplify Path/README.md
@@ -3,6 +3,7 @@
[English Version](/solution/0000-0099/0071.Simplify%20Path/README_EN.md)
## 题目描述
+
以 Unix 风格给出一个文件的绝对路径,你需要简化它。或者换句话说,将其转换为规范路径。
@@ -50,15 +51,14 @@
输入:"/a//b////c/d//././/.."
输出:"/a/b/c"
-
-
## 解法
-
+
### **Python3**
+
```python
@@ -66,6 +66,7 @@
```
### **Java**
+
```java
@@ -73,8 +74,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0071.Simplify Path/README_EN.md b/solution/0000-0099/0071.Simplify Path/README_EN.md
index 00db64d63005d..6251a4df2fc60 100644
--- a/solution/0000-0099/0071.Simplify Path/README_EN.md
+++ b/solution/0000-0099/0071.Simplify Path/README_EN.md
@@ -3,26 +3,17 @@
[中文文档](/solution/0000-0099/0071.Simplify%20Path/README.md)
## Description
-Given an absolute path for a file (Unix-style), simplify it. Or in other words, convert it to the canonical path.
-
+Given an absolute path for a file (Unix-style), simplify it. Or in other words, convert it to the canonical path.
In a UNIX-style file system, a period .
refers to the current directory. Furthermore, a double period ..
moves the directory up a level. For more information, see: Absolute path vs relative path in Linux/Unix
-
-
Note that the returned canonical path must always begin with a slash /
, and there must be only a single slash /
between two directory names. The last directory name (if it exists) must not end with a trailing /
. Also, the canonical path must be the shortest string representing the absolute path.
-
-
-
-
Example 1:
-
-
Input: "/home/"
@@ -33,12 +24,8 @@
-
-
Example 2:
-
-
Input: "/../"
@@ -49,12 +36,8 @@
-
-
Example 3:
-
-
Input: "/home//foo/"
@@ -65,12 +48,8 @@
-
-
Example 4:
-
-
Input: "/a/./b/../../c/"
@@ -79,12 +58,8 @@
-
-
Example 5:
-
-
Input: "/a/../../b/../c//.//"
@@ -93,12 +68,8 @@
-
-
Example 6:
-
-
Input: "/a//b////c/d//././/.."
@@ -107,12 +78,8 @@
-
-
-
## Solutions
-
### **Python3**
@@ -128,8 +95,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0072.Edit Distance/README.md b/solution/0000-0099/0072.Edit Distance/README.md
index c28fcbb1c4ddd..c22fff728b59d 100644
--- a/solution/0000-0099/0072.Edit Distance/README.md
+++ b/solution/0000-0099/0072.Edit Distance/README.md
@@ -3,6 +3,7 @@
[English Version](/solution/0000-0099/0072.Edit%20Distance/README_EN.md)
## 题目描述
+
给定两个单词 word1 和 word2,计算出将 word1 转换成 word2 所使用的最少操作数 。
@@ -36,15 +37,14 @@ exention -> exection (将 'n' 替换为 'c')
exection -> execution (插入 'u')
-
-
## 解法
-
+
### **Python3**
+
```python
@@ -52,6 +52,7 @@ exection -> execution (插入 'u')
```
### **Java**
+
```java
@@ -59,8 +60,9 @@ exection -> execution (插入 'u')
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0072.Edit Distance/README_EN.md b/solution/0000-0099/0072.Edit Distance/README_EN.md
index bcdc88394a611..afb5a56137985 100644
--- a/solution/0000-0099/0072.Edit Distance/README_EN.md
+++ b/solution/0000-0099/0072.Edit Distance/README_EN.md
@@ -3,30 +3,23 @@
[中文文档](/solution/0000-0099/0072.Edit%20Distance/README.md)
## Description
-Given two words word1 and word2, find the minimum number of operations required to convert word1 to word2.
-
+Given two words word1 and word2, find the minimum number of operations required to convert word1 to word2.
You have the following 3 operations permitted on a word:
-
-
- - Insert a character
+ - Insert a character
- - Delete a character
+ - Delete a character
- - Replace a character
+ - Replace a character
-
-
Example 1:
-
-
Input: word1 = "horse", word2 = "ros"
@@ -43,12 +36,8 @@ rose -> ros (remove 'e')
-
-
Example 2:
-
-
Input: word1 = "intention", word2 = "execution"
@@ -69,12 +58,8 @@ exection -> execution (insert 'u')
-
-
-
## Solutions
-
### **Python3**
@@ -90,8 +75,9 @@ exection -> execution (insert 'u')
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0073.Set Matrix Zeroes/README.md b/solution/0000-0099/0073.Set Matrix Zeroes/README.md
index 1f8efbb10a16e..85b69831f3e4a 100644
--- a/solution/0000-0099/0073.Set Matrix Zeroes/README.md
+++ b/solution/0000-0099/0073.Set Matrix Zeroes/README.md
@@ -3,6 +3,7 @@
[English Version](/solution/0000-0099/0073.Set%20Matrix%20Zeroes/README_EN.md)
## 题目描述
+
给定一个 m x n 的矩阵,如果一个元素为 0,则将其所在行和列的所有元素都设为 0。请使用原地算法。
@@ -45,15 +46,14 @@
你能想出一个常数空间的解决方案吗?
-
-
## 解法
-
+
### **Python3**
+
```python
@@ -61,6 +61,7 @@
```
### **Java**
+
```java
@@ -68,8 +69,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0073.Set Matrix Zeroes/README_EN.md b/solution/0000-0099/0073.Set Matrix Zeroes/README_EN.md
index 0d09cb4a4550f..92aa575bb34bc 100644
--- a/solution/0000-0099/0073.Set Matrix Zeroes/README_EN.md
+++ b/solution/0000-0099/0073.Set Matrix Zeroes/README_EN.md
@@ -3,14 +3,11 @@
[中文文档](/solution/0000-0099/0073.Set%20Matrix%20Zeroes/README.md)
## Description
-Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in-place.
-
+Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in-place.
Example 1:
-
-
Input:
@@ -39,12 +36,8 @@
-
-
Example 2:
-
-
Input:
@@ -73,28 +66,20 @@
-
-
Follow up:
-
-
- - A straight forward solution using O(mn) space is probably a bad idea.
+ - A straight forward solution using O(mn) space is probably a bad idea.
- - A simple improvement uses O(m + n) space, but still not the best solution.
+ - A simple improvement uses O(m + n) space, but still not the best solution.
- - Could you devise a constant space solution?
+ - Could you devise a constant space solution?
-
-
-
## Solutions
-
### **Python3**
@@ -110,8 +95,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0074.Search a 2D Matrix/README.md b/solution/0000-0099/0074.Search a 2D Matrix/README.md
index 0fde83b4965a4..068a7ec9564b6 100644
--- a/solution/0000-0099/0074.Search a 2D Matrix/README.md
+++ b/solution/0000-0099/0074.Search a 2D Matrix/README.md
@@ -3,6 +3,7 @@
[English Version](/solution/0000-0099/0074.Search%20a%202D%20Matrix/README_EN.md)
## 题目描述
+
编写一个高效的算法来判断 m x n 矩阵中,是否存在一个目标值。该矩阵具有如下特性:
@@ -34,15 +35,14 @@ matrix = [
target = 13
输出: false
-
-
## 解法
-
+
### **Python3**
+
```python
@@ -50,6 +50,7 @@ target = 13
```
### **Java**
+
```java
@@ -57,8 +58,9 @@ target = 13
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0074.Search a 2D Matrix/README_EN.md b/solution/0000-0099/0074.Search a 2D Matrix/README_EN.md
index 50497987cafaa..ad1ab41b02480 100644
--- a/solution/0000-0099/0074.Search a 2D Matrix/README_EN.md
+++ b/solution/0000-0099/0074.Search a 2D Matrix/README_EN.md
@@ -3,24 +3,19 @@
[中文文档](/solution/0000-0099/0074.Search%20a%202D%20Matrix/README.md)
## Description
-Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:
-
+Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:
- - Integers in each row are sorted from left to right.
+ - Integers in each row are sorted from left to right.
- - The first integer of each row is greater than the last integer of the previous row.
+ - The first integer of each row is greater than the last integer of the previous row.
-
-
Example 1:
-
-
Input:
@@ -41,12 +36,8 @@ target = 3
-
-
Example 2:
-
-
Input:
@@ -65,12 +56,8 @@ target = 13
Output: false
-
-
-
## Solutions
-
### **Python3**
@@ -86,8 +73,9 @@ target = 13
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0075.Sort Colors/README.md b/solution/0000-0099/0075.Sort Colors/README.md
index 0e28312ab4ded..02320a0d046c8 100644
--- a/solution/0000-0099/0075.Sort Colors/README.md
+++ b/solution/0000-0099/0075.Sort Colors/README.md
@@ -3,6 +3,7 @@
[English Version](/solution/0000-0099/0075.Sort%20Colors/README_EN.md)
## 题目描述
+
给定一个包含红色、白色和蓝色,一共 n 个元素的数组,原地对它们进行排序,使得相同颜色的元素相邻,并按照红色、白色、蓝色顺序排列。
@@ -24,15 +25,14 @@
你能想出一个仅使用常数空间的一趟扫描算法吗?
-
-
## 解法
-
+
### **Python3**
+
```python
@@ -40,6 +40,7 @@
```
### **Java**
+
```java
@@ -47,8 +48,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0075.Sort Colors/README_EN.md b/solution/0000-0099/0075.Sort Colors/README_EN.md
index bbe83042d614d..892b9b739727d 100644
--- a/solution/0000-0099/0075.Sort Colors/README_EN.md
+++ b/solution/0000-0099/0075.Sort Colors/README_EN.md
@@ -3,50 +3,35 @@
[中文文档](/solution/0000-0099/0075.Sort%20Colors/README.md)
## Description
-Given an array with n objects colored red, white or blue, sort them in-place so that objects of the same color are adjacent, with the colors in the order red, white and blue.
-
+Given an array with n objects colored red, white or blue, sort them in-place so that objects of the same color are adjacent, with the colors in the order red, white and blue.
Here, we will use the integers 0, 1, and 2 to represent the color red, white, and blue respectively.
-
-
Note: You are not suppose to use the library's sort function for this problem.
-
-
Example:
-
-
Input: [2,0,2,1,1,0]
Output: [0,0,1,1,2,2]
-
-
Follow up:
-
-
- - A rather straight forward solution is a two-pass algorithm using counting sort.
+ - A rather straight forward solution is a two-pass algorithm using counting sort.
- First, iterate the array counting number of 0's, 1's, and 2's, then overwrite array with total number of 0's, then 1's and followed by 2's.
+ First, iterate the array counting number of 0's, 1's, and 2's, then overwrite array with total number of 0's, then 1's and followed by 2's.
- - Could you come up with a one-pass algorithm using only constant space?
+ - Could you come up with a one-pass algorithm using only constant space?
-
-
-
## Solutions
-
### **Python3**
@@ -62,8 +47,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0076.Minimum Window Substring/README.md b/solution/0000-0099/0076.Minimum Window Substring/README.md
index 34e7d93818c28..a0ff683747f85 100644
--- a/solution/0000-0099/0076.Minimum Window Substring/README.md
+++ b/solution/0000-0099/0076.Minimum Window Substring/README.md
@@ -3,6 +3,7 @@
[English Version](/solution/0000-0099/0076.Minimum%20Window%20Substring/README_EN.md)
## 题目描述
+
给你一个字符串 S、一个字符串 T,请在字符串 S 里面找出:包含 T 所有字母的最小子串。
@@ -18,15 +19,14 @@
如果 S 中存在这样的子串,我们保证它是唯一的答案。
-
-
## 解法
-
+
### **Python3**
+
```python
@@ -34,6 +34,7 @@
```
### **Java**
+
```java
@@ -41,8 +42,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0076.Minimum Window Substring/README_EN.md b/solution/0000-0099/0076.Minimum Window Substring/README_EN.md
index 80534f0c34e79..c61ecc773ebcc 100644
--- a/solution/0000-0099/0076.Minimum Window Substring/README_EN.md
+++ b/solution/0000-0099/0076.Minimum Window Substring/README_EN.md
@@ -3,14 +3,11 @@
[中文文档](/solution/0000-0099/0076.Minimum%20Window%20Substring/README.md)
## Description
-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).
-
+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).
Example:
-
-
Input: S = "ADOBECODEBANC", T = "ABC"
@@ -19,26 +16,18 @@
-
-
Note:
-
-
- - If there is no such window in S that covers all characters in T, return the empty string
""
.
+ - If there is no such window in S that covers all characters in T, return the empty string
""
.
- - If there is such window, you are guaranteed that there will always be only one unique minimum window in S.
+ - If there is such window, you are guaranteed that there will always be only one unique minimum window in S.
-
-
-
## Solutions
-
### **Python3**
@@ -54,8 +43,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0077.Combinations/README.md b/solution/0000-0099/0077.Combinations/README.md
index 50d5b83c98954..de6bd19ef79a5 100644
--- a/solution/0000-0099/0077.Combinations/README.md
+++ b/solution/0000-0099/0077.Combinations/README.md
@@ -3,6 +3,7 @@
[English Version](/solution/0000-0099/0077.Combinations/README_EN.md)
## 题目描述
+
给定两个整数 n 和 k,返回 1 ... n 中所有可能的 k 个数的组合。
@@ -19,15 +20,14 @@
[1,4],
]
-
-
## 解法
-
+
### **Python3**
+
```python
@@ -35,6 +35,7 @@
```
### **Java**
+
```java
@@ -42,8 +43,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0077.Combinations/README_EN.md b/solution/0000-0099/0077.Combinations/README_EN.md
index 001a30305c770..67dab32bf425c 100644
--- a/solution/0000-0099/0077.Combinations/README_EN.md
+++ b/solution/0000-0099/0077.Combinations/README_EN.md
@@ -3,14 +3,11 @@
[中文文档](/solution/0000-0099/0077.Combinations/README.md)
## Description
-Given two integers n and k, return all possible combinations of k numbers out of 1 ... n.
-
+Given two integers n and k, return all possible combinations of k numbers out of 1 ... n.
Example:
-
-
Input: n = 4, k = 2
@@ -35,12 +32,8 @@
-
-
-
## Solutions
-
### **Python3**
@@ -56,8 +49,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0078.Subsets/README.md b/solution/0000-0099/0078.Subsets/README.md
index 9f139cde15a56..59590a4d782b0 100644
--- a/solution/0000-0099/0078.Subsets/README.md
+++ b/solution/0000-0099/0078.Subsets/README.md
@@ -3,6 +3,7 @@
[English Version](/solution/0000-0099/0078.Subsets/README_EN.md)
## 题目描述
+
给定一组不含重复元素的整数数组 nums,返回该数组所有可能的子集(幂集)。
@@ -23,15 +24,14 @@
[]
]
-
-
## 解法
-
+
### **Python3**
+
```python
@@ -39,6 +39,7 @@
```
### **Java**
+
```java
@@ -46,8 +47,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0078.Subsets/README_EN.md b/solution/0000-0099/0078.Subsets/README_EN.md
index 7e50c1e684fe5..b85820e6cc206 100644
--- a/solution/0000-0099/0078.Subsets/README_EN.md
+++ b/solution/0000-0099/0078.Subsets/README_EN.md
@@ -3,18 +3,13 @@
[中文文档](/solution/0000-0099/0078.Subsets/README.md)
## Description
-Given a set of distinct integers, nums, return all possible subsets (the power set).
-
+Given a set of distinct integers, nums, return all possible subsets (the power set).
Note: The solution set must not contain duplicate subsets.
-
-
Example:
-
-
Input: nums = [1,2,3]
@@ -41,12 +36,8 @@
]
-
-
-
## Solutions
-
### **Python3**
@@ -62,8 +53,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0079.Word Search/README.md b/solution/0000-0099/0079.Word Search/README.md
index 1be49f6a2ae38..f904152f9b777 100644
--- a/solution/0000-0099/0079.Word Search/README.md
+++ b/solution/0000-0099/0079.Word Search/README.md
@@ -3,6 +3,7 @@
[English Version](/solution/0000-0099/0079.Word%20Search/README_EN.md)
## 题目描述
+
给定一个二维网格和一个单词,找出该单词是否存在于网格中。
@@ -34,15 +35,14 @@
1 <= word.length <= 10^3
-
-
## 解法
-
+
### **Python3**
+
```python
@@ -50,6 +50,7 @@
```
### **Java**
+
```java
@@ -57,8 +58,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0079.Word Search/README_EN.md b/solution/0000-0099/0079.Word Search/README_EN.md
index a66450fff14e1..cbf5dcf2c0d1f 100644
--- a/solution/0000-0099/0079.Word Search/README_EN.md
+++ b/solution/0000-0099/0079.Word Search/README_EN.md
@@ -3,18 +3,13 @@
[中文文档](/solution/0000-0099/0079.Word%20Search/README.md)
## Description
-Given a 2D board and a word, find if the word exists in the grid.
-
+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 neighboring. The same letter cell may not be used more than once.
-
-
Example:
-
-
board =
@@ -39,7 +34,6 @@ Given word = "ABCB", return false.
-
Constraints:
@@ -50,11 +44,8 @@ Given word = "ABCB", return false.
1 <= word.length <= 10^3
-
-
## Solutions
-
### **Python3**
@@ -70,8 +61,9 @@ Given word = "ABCB", return false.
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0080.Remove Duplicates from Sorted Array II/README.md b/solution/0000-0099/0080.Remove Duplicates from Sorted Array II/README.md
index 782b614b44d12..7ba14fc924ba5 100644
--- a/solution/0000-0099/0080.Remove Duplicates from Sorted Array II/README.md
+++ b/solution/0000-0099/0080.Remove Duplicates from Sorted Array II/README.md
@@ -3,6 +3,7 @@
[English Version](/solution/0000-0099/0080.Remove%20Duplicates%20from%20Sorted%20Array%20II/README_EN.md)
## 题目描述
+
给定一个排序数组,你需要在原地删除重复出现的元素,使得每个元素最多出现两次,返回移除后数组的新长度。
@@ -42,15 +43,14 @@ for (int i = 0; i < len; i++) {
print(nums[i]);
}
-
-
## 解法
-
+
### **Python3**
+
```python
@@ -58,6 +58,7 @@ for (int i = 0; i < len; i++) {
```
### **Java**
+
```java
@@ -65,8 +66,9 @@ for (int i = 0; i < len; i++) {
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0080.Remove Duplicates from Sorted Array II/README_EN.md b/solution/0000-0099/0080.Remove Duplicates from Sorted Array II/README_EN.md
index 99e3b60dcc04e..c88cd411c432f 100644
--- a/solution/0000-0099/0080.Remove Duplicates from Sorted Array II/README_EN.md
+++ b/solution/0000-0099/0080.Remove Duplicates from Sorted Array II/README_EN.md
@@ -3,18 +3,13 @@
[中文文档](/solution/0000-0099/0080.Remove%20Duplicates%20from%20Sorted%20Array%20II/README.md)
## Description
-Given a sorted array nums, remove the duplicates in-place such that duplicates appeared at most twice and return the new length.
-
+Given a sorted array nums, remove the duplicates in-place such that duplicates appeared at most twice and return the new length.
Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory.
-
-
Example 1:
-
-
Given nums = [1,1,1,2,2,3],
@@ -27,12 +22,8 @@ Your function should return length = 5
, with the f
It doesn't matter what you leave beyond the returned length.
-
-
Example 2:
-
-
Given nums = [0,0,1,1,1,1,2,3,3],
@@ -47,24 +38,14 @@ It doesn't matter what values are set beyond the returned length.
-
-
Clarification:
-
-
Confused why the returned value is an integer but your answer is an array?
-
-
Note that the input array is passed in by reference, which means modification to the input array will be known to the caller as well.
-
-
Internally you can think of this:
-
-
// nums is passed in by reference. (i.e., without making a copy)
@@ -85,12 +66,8 @@ for (int i = 0; i < len; i++) {
-
-
-
## Solutions
-
### **Python3**
@@ -106,8 +83,9 @@ for (int i = 0; i < len; i++) {
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0081.Search in Rotated Sorted Array II/README.md b/solution/0000-0099/0081.Search in Rotated Sorted Array II/README.md
index b58718d9f6668..e809839e984b3 100644
--- a/solution/0000-0099/0081.Search in Rotated Sorted Array II/README.md
+++ b/solution/0000-0099/0081.Search in Rotated Sorted Array II/README.md
@@ -3,6 +3,7 @@
[English Version](/solution/0000-0099/0081.Search%20in%20Rotated%20Sorted%20Array%20II/README_EN.md)
## 题目描述
+
假设按照升序排序的数组在预先未知的某个点上进行了旋转。
@@ -28,15 +29,14 @@
这会影响到程序的时间复杂度吗?会有怎样的影响,为什么?
-
-
## 解法
-
+
### **Python3**
+
```python
@@ -44,6 +44,7 @@
```
### **Java**
+
```java
@@ -51,8 +52,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0081.Search in Rotated Sorted Array II/README_EN.md b/solution/0000-0099/0081.Search in Rotated Sorted Array II/README_EN.md
index d17a8bd16cc27..d5146e10c3f4b 100644
--- a/solution/0000-0099/0081.Search in Rotated Sorted Array II/README_EN.md
+++ b/solution/0000-0099/0081.Search in Rotated Sorted Array II/README_EN.md
@@ -3,22 +3,15 @@
[中文文档](/solution/0000-0099/0081.Search%20in%20Rotated%20Sorted%20Array%20II/README.md)
## Description
-Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.
-
+Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.
(i.e., [0,0,1,2,2,5,6]
might become [2,5,6,0,0,1,2]
).
-
-
You are given a target value to search. If found in the array return true
, otherwise return false
.
-
-
Example 1:
-
-
Input: nums = [2,5,6,0,0,1,2]
, target = 0
@@ -27,38 +20,26 @@
-
-
Example 2:
-
-
Input: nums = [2,5,6,0,0,1,2]
, target = 3
Output: false
-
-
Follow up:
-
-
- - This is a follow up problem to Search in Rotated Sorted Array, where
nums
may contain duplicates.
+ - This is a follow up problem to Search in Rotated Sorted Array, where
nums
may contain duplicates.
- - Would this affect the run-time complexity? How and why?
+ - Would this affect the run-time complexity? How and why?
-
-
-
## Solutions
-
### **Python3**
@@ -74,8 +55,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0082.Remove Duplicates from Sorted List II/README.md b/solution/0000-0099/0082.Remove Duplicates from Sorted List II/README.md
index cc89e3be94b35..7daba867527f3 100644
--- a/solution/0000-0099/0082.Remove Duplicates from Sorted List II/README.md
+++ b/solution/0000-0099/0082.Remove Duplicates from Sorted List II/README.md
@@ -3,6 +3,7 @@
[English Version](/solution/0000-0099/0082.Remove%20Duplicates%20from%20Sorted%20List%20II/README_EN.md)
## 题目描述
+
给定一个排序链表,删除所有含有重复数字的节点,只保留原始链表中 没有重复出现 的数字。
@@ -17,15 +18,14 @@
输入: 1->1->1->2->3
输出: 2->3
-
-
## 解法
-
+
### **Python3**
+
```python
@@ -33,6 +33,7 @@
```
### **Java**
+
```java
@@ -40,8 +41,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0082.Remove Duplicates from Sorted List II/README_EN.md b/solution/0000-0099/0082.Remove Duplicates from Sorted List II/README_EN.md
index 91f6211ecd028..384649825b4ac 100644
--- a/solution/0000-0099/0082.Remove Duplicates from Sorted List II/README_EN.md
+++ b/solution/0000-0099/0082.Remove Duplicates from Sorted List II/README_EN.md
@@ -3,6 +3,7 @@
[中文文档](/solution/0000-0099/0082.Remove%20Duplicates%20from%20Sorted%20List%20II/README.md)
## Description
+
Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list.
Return the linked list sorted as well.
@@ -21,11 +22,8 @@
Output: 2->3
-
-
## Solutions
-
### **Python3**
@@ -41,8 +39,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0083.Remove Duplicates from Sorted List/README.md b/solution/0000-0099/0083.Remove Duplicates from Sorted List/README.md
index 7b20bf4ca7ac2..373ae88a938f0 100644
--- a/solution/0000-0099/0083.Remove Duplicates from Sorted List/README.md
+++ b/solution/0000-0099/0083.Remove Duplicates from Sorted List/README.md
@@ -3,6 +3,7 @@
[English Version](/solution/0000-0099/0083.Remove%20Duplicates%20from%20Sorted%20List/README_EN.md)
## 题目描述
+
给定一个排序链表,删除所有重复的元素,使得每个元素只出现一次。
@@ -17,15 +18,14 @@
输入: 1->1->2->3->3
输出: 1->2->3
-
-
## 解法
-
+
### **Python3**
+
```python
@@ -33,6 +33,7 @@
```
### **Java**
+
```java
@@ -40,8 +41,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0083.Remove Duplicates from Sorted List/README_EN.md b/solution/0000-0099/0083.Remove Duplicates from Sorted List/README_EN.md
index 3c4ceaa0b296f..161032da90493 100644
--- a/solution/0000-0099/0083.Remove Duplicates from Sorted List/README_EN.md
+++ b/solution/0000-0099/0083.Remove Duplicates from Sorted List/README_EN.md
@@ -3,14 +3,11 @@
[中文文档](/solution/0000-0099/0083.Remove%20Duplicates%20from%20Sorted%20List/README.md)
## Description
-Given a sorted linked list, delete all duplicates such that each element appear only once.
-
+Given a sorted linked list, delete all duplicates such that each element appear only once.
Example 1:
-
-
Input: 1->1->2
@@ -19,12 +16,8 @@
-
-
Example 2:
-
-
Input: 1->1->2->3->3
@@ -33,12 +26,8 @@
-
-
-
## Solutions
-
### **Python3**
@@ -54,8 +43,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0083.Remove Duplicates from Sorted List/Solution.js b/solution/0000-0099/0083.Remove Duplicates from Sorted List/Solution.js
index a7236a1b8f10c..7078e3b517e4e 100644
--- a/solution/0000-0099/0083.Remove Duplicates from Sorted List/Solution.js
+++ b/solution/0000-0099/0083.Remove Duplicates from Sorted List/Solution.js
@@ -9,15 +9,14 @@
* @param {ListNode} head
* @return {ListNode}
*/
-var deleteDuplicates = function(head) {
- var p = head;
- while (p && p.next) {
- if (p.val == p.next.val) {
- p.next = p.next.next;
- } else {
- p = p.next;
- }
+var deleteDuplicates = function (head) {
+ var p = head;
+ while (p && p.next) {
+ if (p.val == p.next.val) {
+ p.next = p.next.next;
+ } else {
+ p = p.next;
}
- return head;
-
+ }
+ return head;
};
diff --git a/solution/0000-0099/0084.Largest Rectangle in Histogram/README.md b/solution/0000-0099/0084.Largest Rectangle in Histogram/README.md
index 3366593c5b9ec..84e93ef515c6c 100644
--- a/solution/0000-0099/0084.Largest Rectangle in Histogram/README.md
+++ b/solution/0000-0099/0084.Largest Rectangle in Histogram/README.md
@@ -3,6 +3,7 @@
[English Version](/solution/0000-0099/0084.Largest%20Rectangle%20in%20Histogram/README_EN.md)
## 题目描述
+
给定 n 个非负整数,用来表示柱状图中各个柱子的高度。每个柱子彼此相邻,且宽度为 1 。
@@ -27,15 +28,14 @@
输入: [2,1,5,6,2,3]
输出: 10
-
-
## 解法
-
+
### **Python3**
+
```python
@@ -43,6 +43,7 @@
```
### **Java**
+
```java
@@ -50,8 +51,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0084.Largest Rectangle in Histogram/README_EN.md b/solution/0000-0099/0084.Largest Rectangle in Histogram/README_EN.md
index 0da7efe7724d6..dbd4674955338 100644
--- a/solution/0000-0099/0084.Largest Rectangle in Histogram/README_EN.md
+++ b/solution/0000-0099/0084.Largest Rectangle in Histogram/README_EN.md
@@ -3,36 +3,25 @@
[中文文档](/solution/0000-0099/0084.Largest%20Rectangle%20in%20Histogram/README.md)
## Description
-Given n non-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangle in the histogram.
+Given n non-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangle in the histogram.
-

Above is a histogram where width of each bar is 1, given height = [2,1,5,6,2,3]
.
-
-
-
-

The largest rectangle is shown in the shaded area, which has area = 10
unit.
-
-
-
-
Example:
-
-
Input: [2,1,5,6,2,3]
@@ -41,12 +30,8 @@
-
-
-
## Solutions
-
### **Python3**
@@ -62,8 +47,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0085.Maximal Rectangle/README.md b/solution/0000-0099/0085.Maximal Rectangle/README.md
index 1ba1ebb27969d..3b72263eb25bd 100644
--- a/solution/0000-0099/0085.Maximal Rectangle/README.md
+++ b/solution/0000-0099/0085.Maximal Rectangle/README.md
@@ -3,6 +3,7 @@
[English Version](/solution/0000-0099/0085.Maximal%20Rectangle/README_EN.md)
## 题目描述
+
给定一个仅包含 0 和 1 的二维二进制矩阵,找出只包含 1 的最大矩形,并返回其面积。
@@ -17,15 +18,14 @@
]
输出: 6
-
-
## 解法
-
+
### **Python3**
+
```python
@@ -33,6 +33,7 @@
```
### **Java**
+
```java
@@ -40,8 +41,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0085.Maximal Rectangle/README_EN.md b/solution/0000-0099/0085.Maximal Rectangle/README_EN.md
index 4b7a91424877b..652eaad17b01f 100644
--- a/solution/0000-0099/0085.Maximal Rectangle/README_EN.md
+++ b/solution/0000-0099/0085.Maximal Rectangle/README_EN.md
@@ -3,14 +3,11 @@
[中文文档](/solution/0000-0099/0085.Maximal%20Rectangle/README.md)
## Description
-Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing only 1's and return its area.
-
+Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing only 1's and return its area.
Example:
-
-
Input:
@@ -31,12 +28,8 @@
-
-
-
## Solutions
-
### **Python3**
@@ -52,8 +45,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0086.Partition List/README.md b/solution/0000-0099/0086.Partition List/README.md
index e44fb2c97e45f..288f7ce8604bc 100644
--- a/solution/0000-0099/0086.Partition List/README.md
+++ b/solution/0000-0099/0086.Partition List/README.md
@@ -3,6 +3,7 @@
[English Version](/solution/0000-0099/0086.Partition%20List/README_EN.md)
## 题目描述
+
给定一个链表和一个特定值 x,对链表进行分隔,使得所有小于 x 的节点都在大于或等于 x 的节点之前。
@@ -14,15 +15,14 @@
输出: 1->2->2->4->3->5
-
-
## 解法
-
+
### **Python3**
+
```python
@@ -30,6 +30,7 @@
```
### **Java**
+
```java
@@ -37,8 +38,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0086.Partition List/README_EN.md b/solution/0000-0099/0086.Partition List/README_EN.md
index 45b2ce274a78f..81784efe4d78f 100644
--- a/solution/0000-0099/0086.Partition List/README_EN.md
+++ b/solution/0000-0099/0086.Partition List/README_EN.md
@@ -3,18 +3,13 @@
[中文文档](/solution/0000-0099/0086.Partition%20List/README.md)
## Description
-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.
-
+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 order of the nodes in each of the two partitions.
-
-
Example:
-
-
Input: head = 1->4->3->2->5->2, x = 3
@@ -23,12 +18,8 @@
-
-
-
## Solutions
-
### **Python3**
@@ -44,8 +35,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0087.Scramble String/README.md b/solution/0000-0099/0087.Scramble String/README.md
index 7196b52032834..d08db2d6af261 100644
--- a/solution/0000-0099/0087.Scramble String/README.md
+++ b/solution/0000-0099/0087.Scramble String/README.md
@@ -3,6 +3,7 @@
[English Version](/solution/0000-0099/0087.Scramble%20String/README_EN.md)
## 题目描述
+
给定一个字符串 s1,我们可以把它递归地分割成两个非空子字符串,从而将其表示为二叉树。
@@ -58,15 +59,14 @@ r g ta e
输入: s1 = "abcde", s2 = "caebd"
输出: false
-
-
## 解法
-
+
### **Python3**
+
```python
@@ -74,6 +74,7 @@ r g ta e
```
### **Java**
+
```java
@@ -81,8 +82,9 @@ r g ta e
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0087.Scramble String/README_EN.md b/solution/0000-0099/0087.Scramble String/README_EN.md
index c6948694098fc..e436b9c98e893 100644
--- a/solution/0000-0099/0087.Scramble String/README_EN.md
+++ b/solution/0000-0099/0087.Scramble String/README_EN.md
@@ -3,14 +3,11 @@
[中文文档](/solution/0000-0099/0087.Scramble%20String/README.md)
## Description
-Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively.
-
+Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively.
Below is one possible representation of s1 = "great"
:
-
-
great
@@ -29,16 +26,10 @@ g r e at
-
-
To scramble the string, we may choose any non-leaf node and swap its two children.
-
-
For example, if we choose the node "gr"
and swap its two children, it produces a scrambled string "rgeat"
.
-
-
rgeat
@@ -57,16 +48,10 @@ r g e at
-
-
We say that "rgeat"
is a scrambled string of "great"
.
-
-
Similarly, if we continue to swap the children of nodes "eat"
and "at"
, it produces a scrambled string "rgtae"
.
-
-
rgtae
@@ -85,20 +70,12 @@ r g ta e
-
-
We say that "rgtae"
is a scrambled string of "great"
.
-
-
Given two strings s1 and s2 of the same length, determine if s2 is a scrambled string of s1.
-
-
Example 1:
-
-
Input: s1 = "great", s2 = "rgeat"
@@ -107,24 +84,16 @@ r g ta e
-
-
Example 2:
-
-
Input: s1 = "abcde", s2 = "caebd"
Output: false
-
-
-
## Solutions
-
### **Python3**
@@ -140,8 +109,9 @@ r g ta e
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0088.Merge Sorted Array/README.md b/solution/0000-0099/0088.Merge Sorted Array/README.md
index 3306d81aee89e..47b8c97754174 100644
--- a/solution/0000-0099/0088.Merge Sorted Array/README.md
+++ b/solution/0000-0099/0088.Merge Sorted Array/README.md
@@ -3,6 +3,7 @@
[English Version](/solution/0000-0099/0088.Merge%20Sorted%20Array/README_EN.md)
## 题目描述
+
给你两个有序整数数组 nums1 和 nums2,请你将 nums2 合并到 nums1 中,使 num1 成为一个有序数组。
@@ -25,15 +26,14 @@ nums2 = [2,5,6], n = 3
输出: [1,2,2,3,5,6]
-
-
## 解法
-
+
### **Python3**
+
```python
@@ -41,6 +41,7 @@ nums2 = [2,5,6], n = 3
```
### **Java**
+
```java
@@ -48,8 +49,9 @@ nums2 = [2,5,6], n = 3
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0088.Merge Sorted Array/README_EN.md b/solution/0000-0099/0088.Merge Sorted Array/README_EN.md
index c880ae610b72f..25ce1c29a2d53 100644
--- a/solution/0000-0099/0088.Merge Sorted Array/README_EN.md
+++ b/solution/0000-0099/0088.Merge Sorted Array/README_EN.md
@@ -3,28 +3,21 @@
[中文文档](/solution/0000-0099/0088.Merge%20Sorted%20Array/README.md)
## Description
-Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.
-
+Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.
Note:
-
-
- - The number of elements initialized in nums1 and nums2 are m and n respectively.
+ - The number of elements initialized in nums1 and nums2 are m and n respectively.
- - You may assume that nums1 has enough space (size that is greater or equal to m + n) to hold additional elements from nums2.
+ - You may assume that nums1 has enough space (size that is greater or equal to m + n) to hold additional elements from nums2.
-
-
Example:
-
-
Input:
@@ -39,10 +32,8 @@ nums2 = [2,5,6], n = 3
-
## Solutions
-
### **Python3**
@@ -58,8 +49,9 @@ nums2 = [2,5,6], n = 3
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0088.Merge Sorted Array/Solution.js b/solution/0000-0099/0088.Merge Sorted Array/Solution.js
index 5079f28b336ae..c58e56f83a7dd 100644
--- a/solution/0000-0099/0088.Merge Sorted Array/Solution.js
+++ b/solution/0000-0099/0088.Merge Sorted Array/Solution.js
@@ -1,39 +1,40 @@
//beat 88%
-const merge1 = function(nums1, m, nums2, n){
- const arr = nums1.slice(0,m);
- let i = 0, j = 0;
+const merge1 = function (nums1, m, nums2, n) {
+ const arr = nums1.slice(0, m);
+ let i = 0,
+ j = 0;
let count = 0;
- while(i < m && j < n){
- if(arr[i] <= nums2[j]){
+ while (i < m && j < n) {
+ if (arr[i] <= nums2[j]) {
nums1[count++] = arr[i++];
- }else{
+ } else {
nums1[count++] = nums2[j++];
}
}
- while(i < m){
+ while (i < m) {
nums1[count++] = arr[i++];
}
- while(j < n){
+ while (j < n) {
nums1[count++] = nums2[j++];
}
};
//beat 30%....
-const merge = function(nums1, m, nums2,n){
+const merge = function (nums1, m, nums2, n) {
let index = m + n - 1;
let aindex = m - 1;
let bindex = n - 1;
- while(aindex >= 0 && bindex >= 0){
- if(nums1[aindex] > nums2[bindex]){
+ while (aindex >= 0 && bindex >= 0) {
+ if (nums1[aindex] > nums2[bindex]) {
nums1[index--] = nums1[aindex--];
- }else{
+ } else {
nums1[index--] = nums2[bindex--];
}
}
- while(aindex >= 0){
+ while (aindex >= 0) {
nums1[index--] = nums1[aindex--];
}
- while(bindex >= 0){
+ while (bindex >= 0) {
nums1[index--] = nums2[bindex--];
}
-};
\ No newline at end of file
+};
diff --git a/solution/0000-0099/0089.Gray Code/README.md b/solution/0000-0099/0089.Gray Code/README.md
index 4d99822445f9b..c22ddd9a1b6d3 100644
--- a/solution/0000-0099/0089.Gray Code/README.md
+++ b/solution/0000-0099/0089.Gray Code/README.md
@@ -3,6 +3,7 @@
[English Version](/solution/0000-0099/0089.Gray%20Code/README_EN.md)
## 题目描述
+
格雷编码是一个二进制数字系统,在该系统中,两个连续的数值仅有一个位数的差异。
@@ -35,15 +36,14 @@
因此,当 n = 0 时,其格雷编码序列为 [0]。
-
-
## 解法
-
+
### **Python3**
+
```python
@@ -51,6 +51,7 @@
```
### **Java**
+
```java
@@ -58,8 +59,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0089.Gray Code/README_EN.md b/solution/0000-0099/0089.Gray Code/README_EN.md
index e81cdceca878b..53f0f9707cd11 100644
--- a/solution/0000-0099/0089.Gray Code/README_EN.md
+++ b/solution/0000-0099/0089.Gray Code/README_EN.md
@@ -3,18 +3,13 @@
[中文文档](/solution/0000-0099/0089.Gray%20Code/README.md)
## Description
-The gray code is a binary numeral system where two successive values differ in only one bit.
- +The gray code is a binary numeral system where two successive values differ in only one bit.
Given a non-negative integer n representing the total number of bits in the code, print the sequence of gray code. A gray code sequence must begin with 0.
- -Example 1:
- -Input: 2 @@ -49,12 +44,8 @@ For example, [0,2,3,1] is also a valid gray code sequence.- -
Example 2:
- -Input: 0 @@ -69,12 +60,8 @@ For example, [0,2,3,1] is also a valid gray code sequence.- - - ## Solutions - ### **Python3** @@ -90,8 +77,9 @@ For example, [0,2,3,1] is also a valid gray code sequence. ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0090.Subsets II/README.md b/solution/0000-0099/0090.Subsets II/README.md index 0a08a88795bbe..70dc6976b951e 100644 --- a/solution/0000-0099/0090.Subsets II/README.md +++ b/solution/0000-0099/0090.Subsets II/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0090.Subsets%20II/README_EN.md) ## 题目描述 +
给定一个可能包含重复元素的整数数组 nums,返回该数组所有可能的子集(幂集)。
@@ -21,15 +22,14 @@ [] ] - - ## 解法 - + ### **Python3** + ```python @@ -37,6 +37,7 @@ ``` ### **Java** + ```java @@ -44,8 +45,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0090.Subsets II/README_EN.md b/solution/0000-0099/0090.Subsets II/README_EN.md index 11d53d3aa59e5..062ab27fab4fd 100644 --- a/solution/0000-0099/0090.Subsets II/README_EN.md +++ b/solution/0000-0099/0090.Subsets II/README_EN.md @@ -3,18 +3,13 @@ [中文文档](/solution/0000-0099/0090.Subsets%20II/README.md) ## Description -Given a collection of integers that might contain duplicates, nums, return all possible subsets (the power set).
- +Given a collection of integers that might contain duplicates, nums, return all possible subsets (the power set).
Note: The solution set must not contain duplicate subsets.
- -Example:
- -Input: [1,2,2] @@ -39,12 +34,8 @@- - - ## Solutions - ### **Python3** @@ -60,8 +51,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0091.Decode Ways/README.md b/solution/0000-0099/0091.Decode Ways/README.md index f95ce72fc1c2a..42c33d68d07f9 100644 --- a/solution/0000-0099/0091.Decode Ways/README.md +++ b/solution/0000-0099/0091.Decode Ways/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0091.Decode%20Ways/README_EN.md) ## 题目描述 +
一条包含字母 A-Z
的消息通过以下方式进行了编码:
A message containing letters from A-Z
is being encoded to numbers using the following mapping:
A message containing letters from A-Z
is being encoded to numbers using the following mapping:
@@ -19,16 +18,10 @@- -
Given a non-empty string containing only digits, determine the total number of ways to decode it.
- -Example 1:
- -Input: "12" @@ -39,12 +32,8 @@- -
Example 2:
- -Input: "226" @@ -53,12 +42,8 @@ Explanation: It could be decoded as "BZ" (2 26), "VF" (22 6), or "BBF" (2 2 6).- - - ## Solutions - ### **Python3** @@ -74,8 +59,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0092.Reverse Linked List II/README.md b/solution/0000-0099/0092.Reverse Linked List II/README.md index 59af2aaaab55d..fc24af1aea79e 100644 --- a/solution/0000-0099/0092.Reverse Linked List II/README.md +++ b/solution/0000-0099/0092.Reverse Linked List II/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0092.Reverse%20Linked%20List%20II/README_EN.md) ## 题目描述 +
反转从位置 m 到 n 的链表。请使用一趟扫描完成反转。
@@ -14,15 +15,14 @@输入: 1->2->3->4->5->NULL, m = 2, n = 4 输出: 1->4->3->2->5->NULL- - ## 解法 - + ### **Python3** + ```python @@ -30,6 +30,7 @@ ``` ### **Java** + ```java @@ -37,8 +38,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0092.Reverse Linked List II/README_EN.md b/solution/0000-0099/0092.Reverse Linked List II/README_EN.md index 07775878ba889..a7b59fee6ae51 100644 --- a/solution/0000-0099/0092.Reverse Linked List II/README_EN.md +++ b/solution/0000-0099/0092.Reverse Linked List II/README_EN.md @@ -3,18 +3,13 @@ [中文文档](/solution/0000-0099/0092.Reverse%20Linked%20List%20II/README.md) ## Description -
Reverse a linked list from position m to n. Do it in one-pass.
- +Reverse a linked list from position m to n. Do it in one-pass.
Note: 1 ≤ m ≤ n ≤ length of list.
- -Example:
- -Input: 1->2->3->4->5->NULL, m = 2, n = 4 @@ -23,12 +18,8 @@- - - ## Solutions - ### **Python3** @@ -44,8 +35,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0093.Restore IP Addresses/README.md b/solution/0000-0099/0093.Restore IP Addresses/README.md index 0ed15a0fa3862..b3c1143e64ea1 100644 --- a/solution/0000-0099/0093.Restore IP Addresses/README.md +++ b/solution/0000-0099/0093.Restore IP Addresses/README.md @@ -1,8 +1,9 @@ -# [93. 复原IP地址](https://leetcode-cn.com/problems/restore-ip-addresses) +# [93. 复原 IP 地址](https://leetcode-cn.com/problems/restore-ip-addresses) [English Version](/solution/0000-0099/0093.Restore%20IP%20Addresses/README_EN.md) ## 题目描述 +
给定一个只包含数字的字符串,复原它并返回所有可能的 IP 地址格式。
@@ -11,15 +12,14 @@输入: "25525511135"
输出: ["255.255.11.135", "255.255.111.35"]
-
-
## 解法
-
+
### **Python3**
+
```python
@@ -27,6 +27,7 @@
```
### **Java**
+
```java
@@ -34,8 +35,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0000-0099/0093.Restore IP Addresses/README_EN.md b/solution/0000-0099/0093.Restore IP Addresses/README_EN.md
index db16c12cb4a1d..d5da0b07c4098 100644
--- a/solution/0000-0099/0093.Restore IP Addresses/README_EN.md
+++ b/solution/0000-0099/0093.Restore IP Addresses/README_EN.md
@@ -3,14 +3,11 @@
[中文文档](/solution/0000-0099/0093.Restore%20IP%20Addresses/README.md)
## Description
-Given a string containing only digits, restore it by returning all possible valid IP address combinations.
- +Given a string containing only digits, restore it by returning all possible valid IP address combinations.
Example:
- -Input: "25525511135" @@ -19,12 +16,8 @@- - - ## Solutions - ### **Python3** @@ -40,8 +33,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0094.Binary Tree Inorder Traversal/README.md b/solution/0000-0099/0094.Binary Tree Inorder Traversal/README.md index 8af4a86bdc4e1..c378de43be22e 100644 --- a/solution/0000-0099/0094.Binary Tree Inorder Traversal/README.md +++ b/solution/0000-0099/0094.Binary Tree Inorder Traversal/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0094.Binary%20Tree%20Inorder%20Traversal/README_EN.md) ## 题目描述 +
给定一个二叉树,返回它的中序 遍历。
@@ -19,15 +20,14 @@进阶: 递归算法很简单,你可以通过迭代算法完成吗?
- - ## 解法 - + ### **Python3** + ```python @@ -35,6 +35,7 @@ ``` ### **Java** + ```java @@ -42,8 +43,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0094.Binary Tree Inorder Traversal/README_EN.md b/solution/0000-0099/0094.Binary Tree Inorder Traversal/README_EN.md index 56984f5cc8df8..7d32fecec87cc 100644 --- a/solution/0000-0099/0094.Binary Tree Inorder Traversal/README_EN.md +++ b/solution/0000-0099/0094.Binary Tree Inorder Traversal/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/solution/0000-0099/0094.Binary%20Tree%20Inorder%20Traversal/README.md) ## Description -Given a binary tree, return the inorder traversal of its nodes' values.
- +Given a binary tree, return the inorder traversal of its nodes' values.
Example:
- -Input: [1,null,2,3] @@ -29,16 +26,10 @@ Output: [1,3,2]- -
Follow up: Recursive solution is trivial, could you do it iteratively?
- - - ## Solutions - ### **Python3** @@ -54,8 +45,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0095.Unique Binary Search Trees II/README.md b/solution/0000-0099/0095.Unique Binary Search Trees II/README.md index 80341cb831f86..56e7ea8dacdf2 100644 --- a/solution/0000-0099/0095.Unique Binary Search Trees II/README.md +++ b/solution/0000-0099/0095.Unique Binary Search Trees II/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0095.Unique%20Binary%20Search%20Trees%20II/README_EN.md) ## 题目描述 +给定一个整数 n,生成所有由 1 ... n 为节点所组成的二叉搜索树。
@@ -27,15 +28,14 @@ 2 1 2 3 - - ## 解法 - + ### **Python3** + ```python @@ -43,6 +43,7 @@ ``` ### **Java** + ```java @@ -50,8 +51,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0095.Unique Binary Search Trees II/README_EN.md b/solution/0000-0099/0095.Unique Binary Search Trees II/README_EN.md index 123b44b4f30c7..38d433039d330 100644 --- a/solution/0000-0099/0095.Unique Binary Search Trees II/README_EN.md +++ b/solution/0000-0099/0095.Unique Binary Search Trees II/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/solution/0000-0099/0095.Unique%20Binary%20Search%20Trees%20II/README.md) ## Description -Given an integer n, generate all structurally unique BST's (binary search trees) that store values 1 ... n.
- +Given an integer n, generate all structurally unique BST's (binary search trees) that store values 1 ... n.
Example:
- -Input: 3 @@ -49,12 +46,8 @@ The above output corresponds to the 5 unique BST's shown below:- - - ## Solutions - ### **Python3** @@ -70,8 +63,9 @@ The above output corresponds to the 5 unique BST's shown below: ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0096.Unique Binary Search Trees/README.md b/solution/0000-0099/0096.Unique Binary Search Trees/README.md index 3bf57e10ec88d..b7f5c05a71dcf 100644 --- a/solution/0000-0099/0096.Unique Binary Search Trees/README.md +++ b/solution/0000-0099/0096.Unique Binary Search Trees/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0096.Unique%20Binary%20Search%20Trees/README_EN.md) ## 题目描述 +
给定一个整数 n,求以 1 ... n 为节点组成的二叉搜索树有多少种?
@@ -19,15 +20,14 @@ / / \ \ 2 1 2 3 - - ## 解法 - + ### **Python3** + ```python @@ -35,6 +35,7 @@ ``` ### **Java** + ```java @@ -42,8 +43,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0096.Unique Binary Search Trees/README_EN.md b/solution/0000-0099/0096.Unique Binary Search Trees/README_EN.md index 3bd2ce868fbb9..3b1132b7dd19b 100644 --- a/solution/0000-0099/0096.Unique Binary Search Trees/README_EN.md +++ b/solution/0000-0099/0096.Unique Binary Search Trees/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/solution/0000-0099/0096.Unique%20Binary%20Search%20Trees/README.md) ## Description -Given n, how many structurally unique BST's (binary search trees) that store values 1 ... n?
- +Given n, how many structurally unique BST's (binary search trees) that store values 1 ... n?
Example:
- -Input: 3 @@ -35,12 +32,8 @@- - - ## Solutions - ### **Python3** @@ -56,8 +49,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0097.Interleaving String/README.md b/solution/0000-0099/0097.Interleaving String/README.md index 1aa1ba2dab625..4075c88291078 100644 --- a/solution/0000-0099/0097.Interleaving String/README.md +++ b/solution/0000-0099/0097.Interleaving String/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0097.Interleaving%20String/README_EN.md) ## 题目描述 +
给定三个字符串 s1, s2, s3, 验证 s3 是否是由 s1 和 s2 交错组成的。
@@ -17,15 +18,14 @@输入: s1 = "aabcc", s2 = "dbbca", s3 = "aadbbbaccc" 输出: false- - ## 解法 - + ### **Python3** + ```python @@ -33,6 +33,7 @@ ``` ### **Java** + ```java @@ -40,8 +41,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0097.Interleaving String/README_EN.md b/solution/0000-0099/0097.Interleaving String/README_EN.md index 50f6cda59a7e7..20799ce25a956 100644 --- a/solution/0000-0099/0097.Interleaving String/README_EN.md +++ b/solution/0000-0099/0097.Interleaving String/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/solution/0000-0099/0097.Interleaving%20String/README.md) ## Description -
Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2.
- +Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2.
Example 1:
- -Input: s1 = "aabcc", s2 = "dbbca", s3 = "aadbbcbcac" @@ -19,12 +16,8 @@- -
Example 2:
- -Input: s1 = "aabcc", s2 = "dbbca", s3 = "aadbbbaccc" @@ -33,12 +26,8 @@- - - ## Solutions - ### **Python3** @@ -54,8 +43,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0098.Validate Binary Search Tree/README.md b/solution/0000-0099/0098.Validate Binary Search Tree/README.md index 7e7a0cd707fed..e861085c7c3ae 100644 --- a/solution/0000-0099/0098.Validate Binary Search Tree/README.md +++ b/solution/0000-0099/0098.Validate Binary Search Tree/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0098.Validate%20Binary%20Search%20Tree/README_EN.md) ## 题目描述 +
给定一个二叉树,判断其是否是一个有效的二叉搜索树。
@@ -36,15 +37,14 @@ 根节点的值为 5 ,但是其右子节点值为 4 。 - - ## 解法 - + ### **Python3** + ```python @@ -52,6 +52,7 @@ ``` ### **Java** + ```java @@ -59,8 +60,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0098.Validate Binary Search Tree/README_EN.md b/solution/0000-0099/0098.Validate Binary Search Tree/README_EN.md index 3ae7a7719cec4..49583b3cae0fb 100644 --- a/solution/0000-0099/0098.Validate Binary Search Tree/README_EN.md +++ b/solution/0000-0099/0098.Validate Binary Search Tree/README_EN.md @@ -3,34 +3,25 @@ [中文文档](/solution/0000-0099/0098.Validate%20Binary%20Search%20Tree/README.md) ## Description -Given a binary tree, determine if it is a valid binary search tree (BST).
- +Given a binary tree, determine if it is a valid binary search tree (BST).
Assume a BST is defined as follows:
- -- -
Example 1:
- -2 @@ -47,12 +38,8 @@- -
Example 2:
- -5 @@ -75,12 +62,8 @@- - - ## Solutions - ### **Python3** @@ -96,8 +79,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0000-0099/0098.Validate Binary Search Tree/Solution.js b/solution/0000-0099/0098.Validate Binary Search Tree/Solution.js index 3041c2dd3d535..e67552a7cfdef 100644 --- a/solution/0000-0099/0098.Validate Binary Search Tree/Solution.js +++ b/solution/0000-0099/0098.Validate Binary Search Tree/Solution.js @@ -9,20 +9,20 @@ * @param {TreeNode} root * @return {boolean} */ -var isValidBST = function(root) { - if (root == null) return true - let arr = [] - inOrderTraverse(root, arr) +var isValidBST = function (root) { + if (root == null) return true; + let arr = []; + inOrderTraverse(root, arr); for (let i = 0; i < arr.length - 1; i++) { - if (arr[i] >= arr[i + 1]) return false + if (arr[i] >= arr[i + 1]) return false; } - return true -} + return true; +}; -var inOrderTraverse = function(node, arr) { +var inOrderTraverse = function (node, arr) { if (node !== null) { - inOrderTraverse(node.left, arr) - arr.push(node.val) - inOrderTraverse(node.right, arr) + inOrderTraverse(node.left, arr); + arr.push(node.val); + inOrderTraverse(node.right, arr); } -} \ No newline at end of file +}; diff --git a/solution/0000-0099/0099.Recover Binary Search Tree/README.md b/solution/0000-0099/0099.Recover Binary Search Tree/README.md index d288d103fdc23..6a7850d48fafc 100644 --- a/solution/0000-0099/0099.Recover Binary Search Tree/README.md +++ b/solution/0000-0099/0099.Recover Binary Search Tree/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0000-0099/0099.Recover%20Binary%20Search%20Tree/README_EN.md) ## 题目描述 +
二叉搜索树中的两个节点被错误地交换。
@@ -52,15 +53,14 @@Two elements of a binary search tree (BST) are swapped by mistake.
- +Two elements of a binary search tree (BST) are swapped by mistake.
Recover the tree without changing its structure.
- -Example 1:
- -Input: [1,3,null,null,2] @@ -49,12 +44,8 @@- -
Example 2:
- -Input: [3,1,4,null,null,2] @@ -89,26 +80,18 @@- -
Follow up:
- -给定两个二叉树,编写一个函数来检验它们是否相同。
@@ -40,15 +41,14 @@ 输出: false - - ## 解法 - + ### **Python3** + ```python @@ -56,6 +56,7 @@ ``` ### **Java** + ```java @@ -63,8 +64,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0100.Same Tree/README_EN.md b/solution/0100-0199/0100.Same Tree/README_EN.md index 368345c29be55..e6f6e43378417 100644 --- a/solution/0100-0199/0100.Same Tree/README_EN.md +++ b/solution/0100-0199/0100.Same Tree/README_EN.md @@ -3,18 +3,13 @@ [中文文档](/solution/0100-0199/0100.Same%20Tree/README.md) ## Description -Given two binary trees, write a function to check if they are the same or not.
- +Given two binary trees, write a function to check if they are the same or not.
Two binary trees are considered the same if they are structurally identical and the nodes have the same value.
- -Example 1:
- -Input: 1 1 @@ -33,12 +28,8 @@- -
Example 2:
- -Input: 1 1 @@ -57,12 +48,8 @@- -
Example 3:
- -Input: 1 1 @@ -81,12 +68,8 @@- - - ## Solutions - ### **Python3** @@ -102,8 +85,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0101.Symmetric Tree/README.md b/solution/0100-0199/0101.Symmetric Tree/README.md index 9ecf7c3272f1a..f10538fda6940 100644 --- a/solution/0100-0199/0101.Symmetric Tree/README.md +++ b/solution/0100-0199/0101.Symmetric Tree/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0101.Symmetric%20Tree/README_EN.md) ## 题目描述 +
给定一个二叉树,检查它是否是镜像对称的。
@@ -28,15 +29,14 @@如果你可以运用递归和迭代两种方法解决这个问题,会很加分。
- - ## 解法 - + ### **Python3** + ```python @@ -44,6 +44,7 @@ ``` ### **Java** + ```java @@ -51,8 +52,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0101.Symmetric Tree/README_EN.md b/solution/0100-0199/0101.Symmetric Tree/README_EN.md index d75f1542a3b6e..d612217ad95fe 100644 --- a/solution/0100-0199/0101.Symmetric Tree/README_EN.md +++ b/solution/0100-0199/0101.Symmetric Tree/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/solution/0100-0199/0101.Symmetric%20Tree/README.md) ## Description -Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).
- +Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).
For example, this binary tree [1,2,2,3,4,4,3]
is symmetric:
1 @@ -25,16 +22,10 @@- -
- -
But the following [1,2,2,null,3,null,3]
is not:
1 @@ -49,22 +40,14 @@- -
- -
Note:
Bonus points if you could solve it both recursively and iteratively.
给定一个二叉树,返回其按层次遍历的节点值。 (即逐层地,从左到右访问所有节点)。
@@ -25,15 +26,14 @@ ] - - ## 解法 - + ### **Python3** + ```python @@ -41,6 +41,7 @@ ``` ### **Java** + ```java @@ -48,8 +49,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0102.Binary Tree Level Order Traversal/README_EN.md b/solution/0100-0199/0102.Binary Tree Level Order Traversal/README_EN.md index e712c78688245..a8920edaeb54f 100644 --- a/solution/0100-0199/0102.Binary Tree Level Order Traversal/README_EN.md +++ b/solution/0100-0199/0102.Binary Tree Level Order Traversal/README_EN.md @@ -3,9 +3,8 @@ [中文文档](/solution/0100-0199/0102.Binary%20Tree%20Level%20Order%20Traversal/README.md) ## Description -Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).
- +Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).
@@ -49,10 +48,8 @@ return its level order traversal as:
给定一个二叉树,返回其节点值的锯齿形层次遍历。(即先从左往右,再从右往左进行下一层遍历,以此类推,层与层之间交替进行)。
@@ -25,15 +26,14 @@ ] - - ## 解法 - + ### **Python3** + ```python @@ -41,6 +41,7 @@ ``` ### **Java** + ```java @@ -48,8 +49,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0103.Binary Tree Zigzag Level Order Traversal/README_EN.md b/solution/0100-0199/0103.Binary Tree Zigzag Level Order Traversal/README_EN.md index 68a038af80b8a..4e3f8261a5b38 100644 --- a/solution/0100-0199/0103.Binary Tree Zigzag Level Order Traversal/README_EN.md +++ b/solution/0100-0199/0103.Binary Tree Zigzag Level Order Traversal/README_EN.md @@ -3,9 +3,8 @@ [中文文档](/solution/0100-0199/0103.Binary%20Tree%20Zigzag%20Level%20Order%20Traversal/README.md) ## Description -Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between).
- +Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between).
@@ -49,10 +48,8 @@ return its zigzag level order traversal as:
给定一个二叉树,找出其最大深度。
@@ -21,15 +22,14 @@返回它的最大深度 3 。
- - ## 解法 - + ### **Python3** + ```python @@ -37,6 +37,7 @@ ``` ### **Java** + ```java @@ -44,8 +45,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0104.Maximum Depth of Binary Tree/README_EN.md b/solution/0100-0199/0104.Maximum Depth of Binary Tree/README_EN.md index a49e7cbf3ae72..0bf52ceb30c3d 100644 --- a/solution/0100-0199/0104.Maximum Depth of Binary Tree/README_EN.md +++ b/solution/0100-0199/0104.Maximum Depth of Binary Tree/README_EN.md @@ -3,26 +3,17 @@ [中文文档](/solution/0100-0199/0104.Maximum%20Depth%20of%20Binary%20Tree/README.md) ## Description -Given a binary tree, find its maximum depth.
- +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 farthest leaf node.
- -Note: A leaf is a node with no children.
- -Example:
- -Given binary tree [3,9,20,null,null,15,7]
,
3 @@ -35,16 +26,10 @@ 15 7- -
return its depth = 3.
- - - ## Solutions - ### **Python3** @@ -60,8 +45,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0104.Maximum Depth of Binary Tree/Solution.js b/solution/0100-0199/0104.Maximum Depth of Binary Tree/Solution.js index acc76d2ef85e0..36003284999dc 100644 --- a/solution/0100-0199/0104.Maximum Depth of Binary Tree/Solution.js +++ b/solution/0100-0199/0104.Maximum Depth of Binary Tree/Solution.js @@ -9,25 +9,28 @@ * @param {TreeNode} root * @return {number} */ -var maxDepth = function(root) { - if (!root) return 0 - let depth = 1 - return search(root,depth) +var maxDepth = function (root) { + if (!root) return 0; + let depth = 1; + return search(root, depth); }; function search(root, depth) { if (!root.left && !root.right) { - return depth + return depth; } else if (root.left && !root.right) { - return search(root.left, depth + 1) + return search(root.left, depth + 1); } else if (root.right && !root.left) { - return search(root.right, depth + 1) + return search(root.right, depth + 1); } else if (root.left && root.right) { - return Math.max(search(root.left, depth+1), search(root.right,depth+1)) + return Math.max( + search(root.left, depth + 1), + search(root.right, depth + 1) + ); } } -var maxDepth2 = function(root) { - if (!root) return 0 - return Math.max(maxDepth(root.left),maxDepth(root.right)) + 1 -} \ No newline at end of file +var maxDepth2 = function (root) { + if (!root) return 0; + return Math.max(maxDepth(root.left), maxDepth(root.right)) + 1; +}; diff --git a/solution/0100-0199/0105.Construct Binary Tree from Preorder and Inorder Traversal/README.md b/solution/0100-0199/0105.Construct Binary Tree from Preorder and Inorder Traversal/README.md index 6fddec0be4b71..cd7da849ab3a2 100644 --- a/solution/0100-0199/0105.Construct Binary Tree from Preorder and Inorder Traversal/README.md +++ b/solution/0100-0199/0105.Construct Binary Tree from Preorder and Inorder Traversal/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0105.Construct%20Binary%20Tree%20from%20Preorder%20and%20Inorder%20Traversal/README_EN.md) ## 题目描述 +根据一棵树的前序遍历与中序遍历构造二叉树。
@@ -22,15 +23,14 @@ / \ 15 7 - - ## 解法 - + ### **Python3** + ```python @@ -38,6 +38,7 @@ ``` ### **Java** + ```java @@ -45,8 +46,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0105.Construct Binary Tree from Preorder and Inorder Traversal/README_EN.md b/solution/0100-0199/0105.Construct Binary Tree from Preorder and Inorder Traversal/README_EN.md index 0ca32b7c6d18b..69f4372cd8caa 100644 --- a/solution/0100-0199/0105.Construct Binary Tree from Preorder and Inorder Traversal/README_EN.md +++ b/solution/0100-0199/0105.Construct Binary Tree from Preorder and Inorder Traversal/README_EN.md @@ -3,32 +3,23 @@ [中文文档](/solution/0100-0199/0105.Construct%20Binary%20Tree%20from%20Preorder%20and%20Inorder%20Traversal/README.md) ## Description -Given preorder and inorder traversal of a tree, construct the binary tree.
- +Given preorder and inorder traversal of a tree, construct the binary tree.
Note:
You may assume that duplicates do not exist in the tree.
For example, given
- -preorder = [3,9,20,15,7] inorder = [9,3,15,20,7]- -
Return the following binary tree:
- -3 @@ -41,12 +32,8 @@ inorder = [9,3,15,20,7]15 7 - - - ## Solutions - ### **Python3** @@ -62,8 +49,9 @@ inorder = [9,3,15,20,7] ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0106.Construct Binary Tree from Inorder and Postorder Traversal/README.md b/solution/0100-0199/0106.Construct Binary Tree from Inorder and Postorder Traversal/README.md index e03b9b9fbba7a..2125864397fb5 100644 --- a/solution/0100-0199/0106.Construct Binary Tree from Inorder and Postorder Traversal/README.md +++ b/solution/0100-0199/0106.Construct Binary Tree from Inorder and Postorder Traversal/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0106.Construct%20Binary%20Tree%20from%20Inorder%20and%20Postorder%20Traversal/README_EN.md) ## 题目描述 +
根据一棵树的中序遍历与后序遍历构造二叉树。
@@ -23,15 +24,14 @@ 15 7 - - ## 解法 - + ### **Python3** + ```python @@ -39,6 +39,7 @@ ``` ### **Java** + ```java @@ -46,8 +47,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0106.Construct Binary Tree from Inorder and Postorder Traversal/README_EN.md b/solution/0100-0199/0106.Construct Binary Tree from Inorder and Postorder Traversal/README_EN.md index f8e65e30dd26f..74d5fdd38d360 100644 --- a/solution/0100-0199/0106.Construct Binary Tree from Inorder and Postorder Traversal/README_EN.md +++ b/solution/0100-0199/0106.Construct Binary Tree from Inorder and Postorder Traversal/README_EN.md @@ -3,32 +3,23 @@ [中文文档](/solution/0100-0199/0106.Construct%20Binary%20Tree%20from%20Inorder%20and%20Postorder%20Traversal/README.md) ## Description -Given inorder and postorder traversal of a tree, construct the binary tree.
- +Given inorder and postorder traversal of a tree, construct the binary tree.
Note:
You may assume that duplicates do not exist in the tree.
For example, given
- -inorder = [9,3,15,20,7] postorder = [9,15,7,20,3]- -
Return the following binary tree:
- -3 @@ -43,12 +34,8 @@ postorder = [9,15,7,20,3]- - - ## Solutions - ### **Python3** @@ -64,8 +51,9 @@ postorder = [9,15,7,20,3] ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0107.Binary Tree Level Order Traversal II/README.md b/solution/0100-0199/0107.Binary Tree Level Order Traversal II/README.md index 157e94c7b16e1..ffc80589a15fc 100644 --- a/solution/0100-0199/0107.Binary Tree Level Order Traversal II/README.md +++ b/solution/0100-0199/0107.Binary Tree Level Order Traversal II/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0107.Binary%20Tree%20Level%20Order%20Traversal%20II/README_EN.md) ## 题目描述 +
给定一个二叉树,返回其节点值自底向上的层次遍历。 (即按从叶子节点所在层到根节点所在的层,逐层从左向右遍历)
@@ -25,15 +26,14 @@ ] - - ## 解法 - + ### **Python3** + ```python @@ -41,6 +41,7 @@ ``` ### **Java** + ```java @@ -48,8 +49,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0107.Binary Tree Level Order Traversal II/README_EN.md b/solution/0100-0199/0107.Binary Tree Level Order Traversal II/README_EN.md index 7a3c0a15f86e7..42006796350ab 100644 --- a/solution/0100-0199/0107.Binary Tree Level Order Traversal II/README_EN.md +++ b/solution/0100-0199/0107.Binary Tree Level Order Traversal II/README_EN.md @@ -3,9 +3,8 @@ [中文文档](/solution/0100-0199/0107.Binary%20Tree%20Level%20Order%20Traversal%20II/README.md) ## Description -Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root).
- +Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root).
@@ -49,10 +48,8 @@ return its bottom-up level order traversal as:
将一个按照升序排列的有序数组,转换为一棵高度平衡二叉搜索树。
@@ -21,15 +22,14 @@ -10 5 - - ## 解法 - + ### **Python3** + ```python @@ -37,6 +37,7 @@ ``` ### **Java** + ```java @@ -44,8 +45,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0108.Convert Sorted Array to Binary Search Tree/README_EN.md b/solution/0100-0199/0108.Convert Sorted Array to Binary Search Tree/README_EN.md index 50ad572b2fae1..76cde842dab9d 100644 --- a/solution/0100-0199/0108.Convert Sorted Array to Binary Search Tree/README_EN.md +++ b/solution/0100-0199/0108.Convert Sorted Array to Binary Search Tree/README_EN.md @@ -3,18 +3,13 @@ [中文文档](/solution/0100-0199/0108.Convert%20Sorted%20Array%20to%20Binary%20Search%20Tree/README.md) ## Description -Given an array where elements are sorted in ascending order, convert it to a height balanced BST.
- +Given an array where elements are sorted in ascending order, convert it to a height balanced BST.
For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never differ by more than 1.
- -Example:
- -Given the sorted array: [-10,-3,0,5,9], @@ -37,12 +32,8 @@ One possible answer is: [0,-3,9,-10,null,5], which represents the following heig- - - ## Solutions - ### **Python3** @@ -58,8 +49,9 @@ One possible answer is: [0,-3,9,-10,null,5], which represents the following heig ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0108.Convert Sorted Array to Binary Search Tree/Solution.js b/solution/0100-0199/0108.Convert Sorted Array to Binary Search Tree/Solution.js index 8ffd2f9ac8f34..6ef60dc3f3c2a 100644 --- a/solution/0100-0199/0108.Convert Sorted Array to Binary Search Tree/Solution.js +++ b/solution/0100-0199/0108.Convert Sorted Array to Binary Search Tree/Solution.js @@ -9,15 +9,15 @@ * @param {number[]} nums * @return {TreeNode} */ -var sortedArrayToBST = function(nums) { - return nums ? buildTree(nums, 0, nums.length - 1) : null +var sortedArrayToBST = function (nums) { + return nums ? buildTree(nums, 0, nums.length - 1) : null; }; -const buildTree = function(nums, left, right) { - if (left > right) return null - let mid = Math.floor((left + right) / 2) - let root = new TreeNode(nums[mid]) - root.left = buildTree(nums, left, mid - 1) - root.right = buildTree(nums, mid + 1, right) - return root -} \ No newline at end of file +const buildTree = function (nums, left, right) { + if (left > right) return null; + let mid = Math.floor((left + right) / 2); + let root = new TreeNode(nums[mid]); + root.left = buildTree(nums, left, mid - 1); + root.right = buildTree(nums, mid + 1, right); + return root; +}; diff --git a/solution/0100-0199/0109.Convert Sorted List to Binary Search Tree/README.md b/solution/0100-0199/0109.Convert Sorted List to Binary Search Tree/README.md index 21b142f40ea9a..5ce855405d27b 100644 --- a/solution/0100-0199/0109.Convert Sorted List to Binary Search Tree/README.md +++ b/solution/0100-0199/0109.Convert Sorted List to Binary Search Tree/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0109.Convert%20Sorted%20List%20to%20Binary%20Search%20Tree/README_EN.md) ## 题目描述 +
给定一个单链表,其中的元素按升序排序,将其转换为高度平衡的二叉搜索树。
@@ -21,15 +22,14 @@ -10 5 - - ## 解法 - + ### **Python3** + ```python @@ -37,6 +37,7 @@ ``` ### **Java** + ```java @@ -44,8 +45,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0109.Convert Sorted List to Binary Search Tree/README_EN.md b/solution/0100-0199/0109.Convert Sorted List to Binary Search Tree/README_EN.md index 6a2eca49d1542..20924e67b9bbc 100644 --- a/solution/0100-0199/0109.Convert Sorted List to Binary Search Tree/README_EN.md +++ b/solution/0100-0199/0109.Convert Sorted List to Binary Search Tree/README_EN.md @@ -3,18 +3,13 @@ [中文文档](/solution/0100-0199/0109.Convert%20Sorted%20List%20to%20Binary%20Search%20Tree/README.md) ## Description -Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.
- +Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.
For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never differ by more than 1.
- -Example:
- -Given the sorted linked list: [-10,-3,0,5,9], @@ -37,12 +32,8 @@ One possible answer is: [0,-3,9,-10,null,5], which represents the following heig- - - ## Solutions - ### **Python3** @@ -58,8 +49,9 @@ One possible answer is: [0,-3,9,-10,null,5], which represents the following heig ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0110.Balanced Binary Tree/README.md b/solution/0100-0199/0110.Balanced Binary Tree/README.md index 51f7e5fee936b..06f4af4d525cd 100644 --- a/solution/0100-0199/0110.Balanced Binary Tree/README.md +++ b/solution/0100-0199/0110.Balanced Binary Tree/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0110.Balanced%20Binary%20Tree/README_EN.md) ## 题目描述 +
给定一个二叉树,判断它是否是高度平衡的二叉树。
@@ -41,15 +42,14 @@- - ## 解法 - + ### **Python3** + ```python @@ -57,6 +57,7 @@ ``` ### **Java** + ```java @@ -64,8 +65,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0110.Balanced Binary Tree/README_EN.md b/solution/0100-0199/0110.Balanced Binary Tree/README_EN.md index abcc8eb133a6c..619c4ff063891 100644 --- a/solution/0100-0199/0110.Balanced Binary Tree/README_EN.md +++ b/solution/0100-0199/0110.Balanced Binary Tree/README_EN.md @@ -3,6 +3,7 @@ [中文文档](/solution/0100-0199/0110.Balanced%20Binary%20Tree/README.md) ## Description +
Given a binary tree, determine if it is height-balanced.
For this problem, a height-balanced binary tree is defined as:
@@ -42,11 +43,8 @@Return false.
- - ## Solutions - ### **Python3** @@ -62,8 +60,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0111.Minimum Depth of Binary Tree/README.md b/solution/0100-0199/0111.Minimum Depth of Binary Tree/README.md index 0359edc04b973..7a536e05255af 100644 --- a/solution/0100-0199/0111.Minimum Depth of Binary Tree/README.md +++ b/solution/0100-0199/0111.Minimum Depth of Binary Tree/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0111.Minimum%20Depth%20of%20Binary%20Tree/README_EN.md) ## 题目描述 +给定一个二叉树,找出其最小深度。
@@ -22,15 +23,14 @@返回它的最小深度 2.
- - ## 解法 - + ### **Python3** + ```python @@ -38,6 +38,7 @@ ``` ### **Java** + ```java @@ -45,8 +46,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0111.Minimum Depth of Binary Tree/README_EN.md b/solution/0100-0199/0111.Minimum Depth of Binary Tree/README_EN.md index e0822a1475ba8..a4fe63c976a7a 100644 --- a/solution/0100-0199/0111.Minimum Depth of Binary Tree/README_EN.md +++ b/solution/0100-0199/0111.Minimum Depth of Binary Tree/README_EN.md @@ -3,26 +3,17 @@ [中文文档](/solution/0100-0199/0111.Minimum%20Depth%20of%20Binary%20Tree/README.md) ## Description -Given a binary tree, find its minimum depth.
- +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 node.
- -Note: A leaf is a node with no children.
- -Example:
- -Given binary tree [3,9,20,null,null,15,7]
,
3 @@ -35,16 +26,10 @@ 15 7- -
return its minimum depth = 2.
- - - ## Solutions - ### **Python3** @@ -60,8 +45,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0112.Path Sum/README.md b/solution/0100-0199/0112.Path Sum/README.md index 2567d5d2aa64f..b7ca033ad435d 100644 --- a/solution/0100-0199/0112.Path Sum/README.md +++ b/solution/0100-0199/0112.Path Sum/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0112.Path%20Sum/README_EN.md) ## 题目描述 +给定一个二叉树和一个目标和,判断该树中是否存在根节点到叶子节点的路径,这条路径上所有节点值相加等于目标和。
@@ -22,15 +23,14 @@返回 true
, 因为存在目标和为 22 的根节点到叶子节点的路径 5->4->11->2
。
Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.
- +Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.
Note: A leaf is a node with no children.
- -Example:
- -Given the below binary tree and sum = 22
,
5 @@ -37,16 +30,10 @@- -
return true, as there exist a root-to-leaf path 5->4->11->2
which sum is 22.
给定一个二叉树和一个目标和,找到所有从根节点到叶子节点路径总和等于给定目标和的路径。
@@ -28,15 +29,14 @@ ] - - ## 解法 - + ### **Python3** + ```python @@ -44,6 +44,7 @@ ``` ### **Java** + ```java @@ -51,8 +52,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0113.Path Sum II/README_EN.md b/solution/0100-0199/0113.Path Sum II/README_EN.md index b369576a594df..118a2940d014f 100644 --- a/solution/0100-0199/0113.Path Sum II/README_EN.md +++ b/solution/0100-0199/0113.Path Sum II/README_EN.md @@ -3,22 +3,15 @@ [中文文档](/solution/0100-0199/0113.Path%20Sum%20II/README.md) ## Description -Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum.
- +Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum.
Note: A leaf is a node with no children.
- -Example:
- -Given the below binary tree and sum = 22
,
5 @@ -37,12 +30,8 @@- -
Return:
- -[ @@ -55,12 +44,8 @@- - - ## Solutions - ### **Python3** @@ -76,8 +61,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0114.Flatten Binary Tree to Linked List/README.md b/solution/0100-0199/0114.Flatten Binary Tree to Linked List/README.md index 22a3389d4b938..a623f39613a34 100644 --- a/solution/0100-0199/0114.Flatten Binary Tree to Linked List/README.md +++ b/solution/0100-0199/0114.Flatten Binary Tree to Linked List/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0114.Flatten%20Binary%20Tree%20to%20Linked%20List/README_EN.md) ## 题目描述 +
给定一个二叉树,原地将它展开为链表。
@@ -28,15 +29,14 @@ \ 6 - - ## 解法 - + ### **Python3** + ```python @@ -44,6 +44,7 @@ ``` ### **Java** + ```java @@ -51,8 +52,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0114.Flatten Binary Tree to Linked List/README_EN.md b/solution/0100-0199/0114.Flatten Binary Tree to Linked List/README_EN.md index 352716c7de4ff..3ed856debda60 100644 --- a/solution/0100-0199/0114.Flatten Binary Tree to Linked List/README_EN.md +++ b/solution/0100-0199/0114.Flatten Binary Tree to Linked List/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/solution/0100-0199/0114.Flatten%20Binary%20Tree%20to%20Linked%20List/README.md) ## Description -Given a binary tree, flatten it to a linked list in-place.
- +Given a binary tree, flatten it to a linked list in-place.
For example, given the following tree:
- -1 @@ -25,12 +22,8 @@- -
The flattened tree should look like:
- -1 @@ -57,12 +50,8 @@- - - ## Solutions - ### **Python3** @@ -78,8 +67,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0115.Distinct Subsequences/README.md b/solution/0100-0199/0115.Distinct Subsequences/README.md index 697791d09b32c..cbef06791fc79 100644 --- a/solution/0100-0199/0115.Distinct Subsequences/README.md +++ b/solution/0100-0199/0115.Distinct Subsequences/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0115.Distinct%20Subsequences/README_EN.md) ## 题目描述 +
给定一个字符串 S 和一个字符串 T,计算在 S 的子序列中 T 出现的个数。
@@ -45,15 +46,14 @@babgbag
^^^
-
-
## 解法
-
+
### **Python3**
+
```python
@@ -61,6 +61,7 @@
```
### **Java**
+
```java
@@ -68,8 +69,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0100-0199/0115.Distinct Subsequences/README_EN.md b/solution/0100-0199/0115.Distinct Subsequences/README_EN.md
index 3e71c0e1f0264..2203e08397a58 100644
--- a/solution/0100-0199/0115.Distinct Subsequences/README_EN.md
+++ b/solution/0100-0199/0115.Distinct Subsequences/README_EN.md
@@ -3,18 +3,13 @@
[中文文档](/solution/0100-0199/0115.Distinct%20Subsequences/README.md)
## Description
-Given a string S and a string T, count the number of distinct subsequences of S which equals T.
- +Given a string S and a string T, count the number of distinct subsequences of S which equals T.
A subsequence of a string is a new string which is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (ie, "ACE"
is a subsequence of "ABCDE"
while "AEC"
is not).
Example 1:
- -Input: S =- -"rabbbit"
, T ="rabbit" @@ -45,12 +40,8 @@ As shown below, there are 3 ways you can generate "rabbit" from S.
Example 2:
- -Input: S =- - - ## Solutions - ### **Python3** @@ -110,8 +97,9 @@ As shown below, there are 5 ways you can generate "bag" from S. ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0116.Populating Next Right Pointers in Each Node/README.md b/solution/0100-0199/0116.Populating Next Right Pointers in Each Node/README.md index fc2c5c82c3524..bf13328542ba9 100644 --- a/solution/0100-0199/0116.Populating Next Right Pointers in Each Node/README.md +++ b/solution/0100-0199/0116.Populating Next Right Pointers in Each Node/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0116.Populating%20Next%20Right%20Pointers%20in%20Each%20Node/README_EN.md) ## 题目描述 +"babgbag"
, T ="bag" @@ -89,12 +80,8 @@ As shown below, there are 5 ways you can generate "bag" from S.
给定一个完美二叉树,其所有叶子节点都在同一层,每个父节点都有两个子节点。二叉树定义如下:
@@ -39,15 +40,14 @@You are given a perfect binary tree where all leaves are on the same level, and every parent has two children. The binary tree has the following definition:
@@ -46,11 +47,8 @@ struct Node {
-1000 <= node.val <= 1000
给定一个二叉树
@@ -50,15 +51,14 @@Given a binary tree
@@ -46,11 +47,8 @@ struct Node {
-100 <= node.val <= 100
给定一个非负整数 numRows,生成杨辉三角的前 numRows 行。
@@ -22,15 +23,14 @@ [1,4,6,4,1] ] - - ## 解法 - + ### **Python3** + ```python @@ -38,6 +38,7 @@ ``` ### **Java** + ```java @@ -45,8 +46,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0118.Pascal's Triangle/README_EN.md b/solution/0100-0199/0118.Pascal's Triangle/README_EN.md index 6de5e56430cc6..67fd49d6efc89 100644 --- a/solution/0100-0199/0118.Pascal's Triangle/README_EN.md +++ b/solution/0100-0199/0118.Pascal's Triangle/README_EN.md @@ -3,20 +3,15 @@ [中文文档](/solution/0100-0199/0118.Pascal's%20Triangle/README.md) ## Description -Given a non-negative integer numRows, generate the first numRows of Pascal's triangle.
- +Given a non-negative integer numRows, generate the first numRows of Pascal's triangle.
In Pascal's triangle, each number is the sum of the two numbers directly above it.
Example:
- -Input: 5 @@ -39,12 +34,8 @@- - - ## Solutions - ### **Python3** @@ -60,8 +51,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0118.Pascal's Triangle/Solution.js b/solution/0100-0199/0118.Pascal's Triangle/Solution.js index 389a05a3cee30..1729352a996ef 100644 --- a/solution/0100-0199/0118.Pascal's Triangle/Solution.js +++ b/solution/0100-0199/0118.Pascal's Triangle/Solution.js @@ -1,33 +1,34 @@ -const generate = function(numRows){ +const generate = function (numRows) { let arr = []; - for(let i = 0; i < numRows; i++){ + for (let i = 0; i < numRows; i++) { let row = []; - row[0]=1; + row[0] = 1; row[i] = 1; - for(let j = 1; j < row.length - 1; j++){ - row[j] = arr[i-1][j-1] + arr[i-1][j]; + for (let j = 1; j < row.length - 1; j++) { + row[j] = arr[i - 1][j - 1] + arr[i - 1][j]; } arr.push(row); } return arr; -} +}; -/** +/** * Author: Mcnwork2018 */ -var generate = function(numRows) { +var generate = function (numRows) { if (numRows === 0) return []; if (numRows === 1) return [[1]]; - if (numRows === 2) return [[1],[1,1]]; - let triangleArray = [[1],[1,1]]; - for ( let i = 2; i < numRows; ++i ) { + if (numRows === 2) return [[1], [1, 1]]; + let triangleArray = [[1], [1, 1]]; + for (let i = 2; i < numRows; ++i) { triangleArray[i] = []; - for ( let j = 0; j < i + 1; ++j ) { - if ( j === 0 || j === i ) { + for (let j = 0; j < i + 1; ++j) { + if (j === 0 || j === i) { triangleArray[i][j] = 1; } else { - triangleArray[i][j] = triangleArray[i-1][j-1] + triangleArray[i-1][j]; + triangleArray[i][j] = + triangleArray[i - 1][j - 1] + triangleArray[i - 1][j]; } } } diff --git a/solution/0100-0199/0119.Pascal's Triangle II/README.md b/solution/0100-0199/0119.Pascal's Triangle II/README.md index 17afbcb40665b..522cc9e20959c 100644 --- a/solution/0100-0199/0119.Pascal's Triangle II/README.md +++ b/solution/0100-0199/0119.Pascal's Triangle II/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0119.Pascal's%20Triangle%20II/README_EN.md) ## 题目描述 +
给定一个非负索引 k,其中 k ≤ 33,返回杨辉三角的第 k 行。
@@ -20,15 +21,14 @@你可以优化你的算法到 O(k) 空间复杂度吗?
- - ## 解法 - + ### **Python3** + ```python @@ -36,6 +36,7 @@ ``` ### **Java** + ```java @@ -43,8 +44,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0119.Pascal's Triangle II/README_EN.md b/solution/0100-0199/0119.Pascal's Triangle II/README_EN.md index 69a04077c4109..80349d60a4575 100644 --- a/solution/0100-0199/0119.Pascal's Triangle II/README_EN.md +++ b/solution/0100-0199/0119.Pascal's Triangle II/README_EN.md @@ -3,24 +3,17 @@ [中文文档](/solution/0100-0199/0119.Pascal's%20Triangle%20II/README.md) ## Description -Given a non-negative index k where k ≤ 33, return the kth index row of the Pascal's triangle.
- +Given a non-negative index k where k ≤ 33, return the kth index row of the Pascal's triangle.
Note that the row index starts from 0.
- -
In Pascal's triangle, each number is the sum of the two numbers directly above it.
Example:
- -Input: 3 @@ -29,20 +22,12 @@- -
Follow up:
- -Could you optimize your algorithm to use only O(k) extra space?
- - - ## Solutions - ### **Python3** @@ -58,8 +43,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0120.Triangle/README.md b/solution/0100-0199/0120.Triangle/README.md index c7424ca2e6810..ecb8b5431907e 100644 --- a/solution/0100-0199/0120.Triangle/README.md +++ b/solution/0100-0199/0120.Triangle/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0120.Triangle/README_EN.md) ## 题目描述 +给定一个三角形,找出自顶向下的最小路径和。每一步只能移动到下一行中相邻的结点上。
@@ -22,15 +23,14 @@如果你可以只使用 O(n) 的额外空间(n 为三角形的总行数)来解决这个问题,那么你的算法会很加分。
- - ## 解法 - + ### **Python3** + ```python @@ -38,6 +38,7 @@ ``` ### **Java** + ```java @@ -45,8 +46,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0120.Triangle/README_EN.md b/solution/0100-0199/0120.Triangle/README_EN.md index 9f040325f4e37..2dd78b2659fe7 100644 --- a/solution/0100-0199/0120.Triangle/README_EN.md +++ b/solution/0100-0199/0120.Triangle/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/solution/0100-0199/0120.Triangle/README.md) ## Description -Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.
- +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
- -[ @@ -27,24 +24,14 @@- -
The minimum path sum from top to bottom is 11
(i.e., 2 + 3 + 5 + 1 = 11).
Note:
- -Bonus point if you are able to do this using only O(n) extra space, where n is the total number of rows in the triangle.
- - - ## Solutions - ### **Python3** @@ -60,8 +47,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0121.Best Time to Buy and Sell Stock/README.md b/solution/0100-0199/0121.Best Time to Buy and Sell Stock/README.md index c1ebcaa461003..16a7bb382e6b9 100644 --- a/solution/0100-0199/0121.Best Time to Buy and Sell Stock/README.md +++ b/solution/0100-0199/0121.Best Time to Buy and Sell Stock/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0121.Best%20Time%20to%20Buy%20and%20Sell%20Stock/README_EN.md) ## 题目描述 +给定一个数组,它的第 i 个元素是一支给定股票第 i 天的价格。
@@ -25,15 +26,14 @@ 解释: 在这种情况下, 没有交易完成, 所以最大利润为 0。 - - ## 解法 - + ### **Python3** + ```python @@ -41,6 +41,7 @@ ``` ### **Java** + ```java @@ -48,8 +49,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0121.Best Time to Buy and Sell Stock/README_EN.md b/solution/0100-0199/0121.Best Time to Buy and Sell Stock/README_EN.md index 61a5de7e54f16..841b2dfa58fde 100644 --- a/solution/0100-0199/0121.Best Time to Buy and Sell Stock/README_EN.md +++ b/solution/0100-0199/0121.Best Time to Buy and Sell Stock/README_EN.md @@ -3,22 +3,15 @@ [中文文档](/solution/0100-0199/0121.Best%20Time%20to%20Buy%20and%20Sell%20Stock/README.md) ## Description -Say you have an array for which the ith element is the price of a given stock on day i.
- +Say you have an array for which the ith element is the price of a given stock on day i.
If you were only permitted to complete at most one transaction (i.e., buy one and sell one share of the stock), design an algorithm to find the maximum profit.
- -Note that you cannot sell a stock before you buy one.
- -Example 1:
- -Input: [7,1,5,3,6,4] @@ -31,12 +24,8 @@- -
Example 2:
- -Input: [7,6,4,3,1] @@ -47,12 +36,8 @@- - - ## Solutions - ### **Python3** @@ -68,8 +53,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0121.Best Time to Buy and Sell Stock/Solution.js b/solution/0100-0199/0121.Best Time to Buy and Sell Stock/Solution.js index 3d987432e802b..c3befd504f155 100644 --- a/solution/0100-0199/0121.Best Time to Buy and Sell Stock/Solution.js +++ b/solution/0100-0199/0121.Best Time to Buy and Sell Stock/Solution.js @@ -1,13 +1,13 @@ -const maxProfit1 = function(prices){ +const maxProfit1 = function (prices) { let min = prices[0]; let profit = 0; - for(let i = 0; i < prices.length; i++){ - if(prices[i] < min){ + for (let i = 0; i < prices.length; i++) { + if (prices[i] < min) { min = prices[i]; } - if(profit < (prices[i] - min)){ + if (profit < prices[i] - min) { profit = prices[i] - min; } } return profit; -} \ No newline at end of file +}; diff --git a/solution/0100-0199/0122.Best Time to Buy and Sell Stock II/README.md b/solution/0100-0199/0122.Best Time to Buy and Sell Stock II/README.md index 0827a65b60c08..b344f71324c62 100644 --- a/solution/0100-0199/0122.Best Time to Buy and Sell Stock II/README.md +++ b/solution/0100-0199/0122.Best Time to Buy and Sell Stock II/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0122.Best%20Time%20to%20Buy%20and%20Sell%20Stock%20II/README_EN.md) ## 题目描述 +
给定一个数组,它的第 i 个元素是一支给定股票第 i 天的价格。
@@ -33,15 +34,14 @@ 输出: 0 解释: 在这种情况下, 没有交易完成, 所以最大利润为 0。 - - ## 解法 - + ### **Python3** + ```python @@ -49,6 +49,7 @@ ``` ### **Java** + ```java @@ -56,8 +57,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0122.Best Time to Buy and Sell Stock II/README_EN.md b/solution/0100-0199/0122.Best Time to Buy and Sell Stock II/README_EN.md index 0ae5643d6a583..370ede8140510 100644 --- a/solution/0100-0199/0122.Best Time to Buy and Sell Stock II/README_EN.md +++ b/solution/0100-0199/0122.Best Time to Buy and Sell Stock II/README_EN.md @@ -3,22 +3,15 @@ [中文文档](/solution/0100-0199/0122.Best%20Time%20to%20Buy%20and%20Sell%20Stock%20II/README.md) ## Description -Say you have an array for which the ith element is the price of a given stock on day i.
- +Say you have an array for which the ith 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 (i.e., buy one and sell one share of the stock multiple times).
- -Note: You may not engage in multiple transactions at the same time (i.e., you must sell the stock before you buy again).
- -Example 1:
- -Input: [7,1,5,3,6,4] @@ -31,12 +24,8 @@- -
Example 2:
- -Input: [1,2,3,4,5] @@ -51,12 +40,8 @@- -
Example 3:
- -Input: [7,6,4,3,1] @@ -65,12 +50,8 @@ Explanation: In this case, no transaction is done, i.e. max profit = 0.- - - ## Solutions - ### **Python3** @@ -86,8 +67,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0122.Best Time to Buy and Sell Stock II/Solution.js b/solution/0100-0199/0122.Best Time to Buy and Sell Stock II/Solution.js index 968e6ce14380d..d00f2b0b639a9 100644 --- a/solution/0100-0199/0122.Best Time to Buy and Sell Stock II/Solution.js +++ b/solution/0100-0199/0122.Best Time to Buy and Sell Stock II/Solution.js @@ -1,9 +1,9 @@ -const maxProfit2 = function(prices){ +const maxProfit2 = function (prices) { let profit = 0; - for(let i = 1; i < prices.length; i++){ - if(prices[i]-prices[i-1] > 0){ - profit+=prices[i]-prices[i-1]; + for (let i = 1; i < prices.length; i++) { + if (prices[i] - prices[i - 1] > 0) { + profit += prices[i] - prices[i - 1]; } } return profit; -} \ No newline at end of file +}; diff --git a/solution/0100-0199/0123.Best Time to Buy and Sell Stock III/README.md b/solution/0100-0199/0123.Best Time to Buy and Sell Stock III/README.md index b256b8aca36cd..f2e64cff93f90 100644 --- a/solution/0100-0199/0123.Best Time to Buy and Sell Stock III/README.md +++ b/solution/0100-0199/0123.Best Time to Buy and Sell Stock III/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0123.Best%20Time%20to%20Buy%20and%20Sell%20Stock%20III/README_EN.md) ## 题目描述 +
给定一个数组,它的第 i 个元素是一支给定的股票在第 i 天的价格。
@@ -32,15 +33,14 @@ 输出: 0 解释: 在这个情况下, 没有交易完成, 所以最大利润为 0。 - - ## 解法 - + ### **Python3** + ```python @@ -48,6 +48,7 @@ ``` ### **Java** + ```java @@ -55,8 +56,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0123.Best Time to Buy and Sell Stock III/README_EN.md b/solution/0100-0199/0123.Best Time to Buy and Sell Stock III/README_EN.md index b4d8d1eca617b..2853c6d76792f 100644 --- a/solution/0100-0199/0123.Best Time to Buy and Sell Stock III/README_EN.md +++ b/solution/0100-0199/0123.Best Time to Buy and Sell Stock III/README_EN.md @@ -3,22 +3,15 @@ [中文文档](/solution/0100-0199/0123.Best%20Time%20to%20Buy%20and%20Sell%20Stock%20III/README.md) ## Description -Say you have an array for which the ith element is the price of a given stock on day i.
- +Say you have an array for which the ith element is the price of a given stock on day i.
Design an algorithm to find the maximum profit. You may complete at most two transactions.
- -Note: You may not engage in multiple transactions at the same time (i.e., you must sell the stock before you buy again).
- -Example 1:
- -Input: [3,3,5,0,0,3,1,4] @@ -29,12 +22,8 @@ Then buy on day 7 (price = 1) and sell on day 8 (price = 4), profit = 4-1 = 3.- -
Example 2:
- -Input: [1,2,3,4,5] @@ -49,12 +38,8 @@- -
Example 3:
- -Input: [7,6,4,3,1] @@ -63,12 +48,8 @@ Explanation: In this case, no transaction is done, i.e. max profit = 0.- - - ## Solutions - ### **Python3** @@ -84,8 +65,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0124.Binary Tree Maximum Path Sum/README.md b/solution/0100-0199/0124.Binary Tree Maximum Path Sum/README.md index 0d666762f8ca9..224b5f10f81f6 100644 --- a/solution/0100-0199/0124.Binary Tree Maximum Path Sum/README.md +++ b/solution/0100-0199/0124.Binary Tree Maximum Path Sum/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0124.Binary%20Tree%20Maximum%20Path%20Sum/README_EN.md) ## 题目描述 +
给定一个非空二叉树,返回其最大路径和。
@@ -31,15 +32,14 @@ 输出: 42 - - ## 解法 - + ### **Python3** + ```python @@ -47,6 +47,7 @@ ``` ### **Java** + ```java @@ -54,8 +55,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0124.Binary Tree Maximum Path Sum/README_EN.md b/solution/0100-0199/0124.Binary Tree Maximum Path Sum/README_EN.md index ecc6ed4fabc43..60ce04d920e91 100644 --- a/solution/0100-0199/0124.Binary Tree Maximum Path Sum/README_EN.md +++ b/solution/0100-0199/0124.Binary Tree Maximum Path Sum/README_EN.md @@ -3,18 +3,13 @@ [中文文档](/solution/0100-0199/0124.Binary%20Tree%20Maximum%20Path%20Sum/README.md) ## Description -Given a non-empty binary tree, find the maximum path sum.
- +Given a non-empty 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 path must contain at least one node and does not need to go through the root.
- -Example 1:
- -Input: [1,2,3] @@ -33,12 +28,8 @@- -
Example 2:
- -Input: [-10,9,20,null,null,15,7] @@ -61,12 +52,8 @@- - - ## Solutions - ### **Python3** @@ -82,8 +69,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0125.Valid Palindrome/README.md b/solution/0100-0199/0125.Valid Palindrome/README.md index 8937571686bc4..03e2fd5fb8451 100644 --- a/solution/0100-0199/0125.Valid Palindrome/README.md +++ b/solution/0100-0199/0125.Valid Palindrome/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0125.Valid%20Palindrome/README_EN.md) ## 题目描述 +
给定一个字符串,验证它是否是回文串,只考虑字母和数字字符,可以忽略字母的大小写。
@@ -20,15 +21,14 @@ 输出: false - - ## 解法 - + ### **Python3** + ```python @@ -36,6 +36,7 @@ ``` ### **Java** + ```java @@ -43,8 +44,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0125.Valid Palindrome/README_EN.md b/solution/0100-0199/0125.Valid Palindrome/README_EN.md index 90cbfcf982972..568b1fb9a3112 100644 --- a/solution/0100-0199/0125.Valid Palindrome/README_EN.md +++ b/solution/0100-0199/0125.Valid Palindrome/README_EN.md @@ -3,18 +3,13 @@ [中文文档](/solution/0100-0199/0125.Valid%20Palindrome/README.md) ## Description -Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.
- +Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.
Note: For the purpose of this problem, we define empty string as valid palindrome.
- -Example 1:
- -Input: "A man, a plan, a canal: Panama" @@ -23,12 +18,8 @@- -
Example 2:
- -Input: "race a car" @@ -37,12 +28,8 @@- - - ## Solutions - ### **Python3** @@ -58,8 +45,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0125.Valid Palindrome/Solution.js b/solution/0100-0199/0125.Valid Palindrome/Solution.js index 7b7829d41c008..f31fb301b557f 100644 --- a/solution/0100-0199/0125.Valid Palindrome/Solution.js +++ b/solution/0100-0199/0125.Valid Palindrome/Solution.js @@ -1,48 +1,50 @@ -const isPalindrome1 = function(s){ - let arr1 = [], arr2 = []; - for(let i = 0; i < s.length; i++){ - if(s[i] >= 'A' && s[i] <= 'Z' ){ +const isPalindrome1 = function (s) { + let arr1 = [], + arr2 = []; + for (let i = 0; i < s.length; i++) { + if (s[i] >= "A" && s[i] <= "Z") { arr1.push(s[i].toLowerCase()); } - if(s[i] >= '0' && s[i] <= '9'|| - s[i] >= 'a' && s[i] <= 'z'){ + if ((s[i] >= "0" && s[i] <= "9") || (s[i] >= "a" && s[i] <= "z")) { arr1.push(s[i]); } } arr2 = [...arr1]; arr2.reverse(); - return arr1.join('') === arr2.join(''); -} + return arr1.join("") === arr2.join(""); +}; -const isPalindrome = function(s){ - function isNumOrAl(a){ - if(a >= 'A' && a <= 'Z' || - a >= '0' && a <= '9'|| - a >= 'a' && a <= 'z'){ +const isPalindrome = function (s) { + function isNumOrAl(a) { + if ( + (a >= "A" && a <= "Z") || + (a >= "0" && a <= "9") || + (a >= "a" && a <= "z") + ) { return true; - } - else{ + } else { return false; } } - if(s.length === 0){ + if (s.length === 0) { return true; } - let i = 0, j = s.length - 1; - while(i < j){ - while(i < j && !isNumOrAl(s[i])){ + let i = 0, + j = s.length - 1; + while (i < j) { + while (i < j && !isNumOrAl(s[i])) { i++; } - while(i < j && !isNumOrAl(s[j])){ + while (i < j && !isNumOrAl(s[j])) { j--; } - if(s[i].toLowerCase() !== s[j].toLowerCase()){ + if (s[i].toLowerCase() !== s[j].toLowerCase()) { return false; - }else{ + } else { i++; j--; } } return true; -}; \ No newline at end of file +}; diff --git a/solution/0100-0199/0126.Word Ladder II/README.md b/solution/0100-0199/0126.Word Ladder II/README.md index 266a881b4b34a..07a111c85ce8e 100644 --- a/solution/0100-0199/0126.Word Ladder II/README.md +++ b/solution/0100-0199/0126.Word Ladder II/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0126.Word%20Ladder%20II/README_EN.md) ## 题目描述 +
给定两个单词(beginWord 和 endWord)和一个字典 wordList,找出所有从 beginWord 到 endWord 的最短转换序列。转换需遵循如下规则:
@@ -46,15 +47,14 @@ wordList = ["hot","dot","dog","lot",&quo 解释: endWord "cog" 不在字典中,所以不存在符合要求的转换序列。 - - ## 解法 - + ### **Python3** + ```python @@ -62,6 +62,7 @@ wordList = ["hot","dot","dog","lot",&quo ``` ### **Java** + ```java @@ -69,8 +70,9 @@ wordList = ["hot","dot","dog","lot",&quo ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0126.Word Ladder II/README_EN.md b/solution/0100-0199/0126.Word Ladder II/README_EN.md index 8945d68e4b420..599d319688121 100644 --- a/solution/0100-0199/0126.Word Ladder II/README_EN.md +++ b/solution/0100-0199/0126.Word Ladder II/README_EN.md @@ -3,44 +3,35 @@ [中文文档](/solution/0100-0199/0126.Word%20Ladder%20II/README.md) ## Description -Given two words (beginWord and endWord), and a dictionary's word list, find all shortest transformation sequence(s) from beginWord to endWord, such that:
- +Given two words (beginWord and endWord), and a dictionary's word list, find all shortest transformation sequence(s) from beginWord to endWord, such that:
Note:
- -Example 1:
- -Input: @@ -65,12 +56,8 @@ wordList = ["hot","dot","dog","lot",&quo- -
Example 2:
- -Input: @@ -91,18 +78,12 @@ wordList = ["hot","dot","dog","lot",&quo- -
给定两个单词(beginWord 和 endWord)和一个字典,找到从 beginWord 到 endWord 的最短转换序列的长度。转换需遵循如下规则:
@@ -45,15 +46,14 @@ wordList = ["hot","dot","dog","lot",&quo 解释: endWord "cog" 不在字典中,所以无法进行转换。 - - ## 解法 - + ### **Python3** + ```python @@ -61,6 +61,7 @@ wordList = ["hot","dot","dog","lot",&quo ``` ### **Java** + ```java @@ -68,8 +69,9 @@ wordList = ["hot","dot","dog","lot",&quo ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0127.Word Ladder/README_EN.md b/solution/0100-0199/0127.Word Ladder/README_EN.md index 5532897e8facb..18cffacc47620 100644 --- a/solution/0100-0199/0127.Word Ladder/README_EN.md +++ b/solution/0100-0199/0127.Word Ladder/README_EN.md @@ -3,44 +3,35 @@ [中文文档](/solution/0100-0199/0127.Word%20Ladder/README.md) ## Description -Given two words (beginWord and endWord), and a dictionary's word list, find the length of shortest transformation sequence from beginWord to endWord, such that:
- +Given two words (beginWord and endWord), and a dictionary's word list, find the length of shortest transformation sequence from beginWord to endWord, such that:
Note:
- -Example 1:
- -Input: @@ -63,12 +54,8 @@ return its length 5.- -
Example 2:
- -Input: @@ -89,18 +76,12 @@ wordList = ["hot","dot","dog","lot",&quo- -
给定一个未排序的整数数组,找出最长连续序列的长度。
@@ -14,15 +15,14 @@ 输出: 4 解释: 最长连续序列是[1, 2, 3, 4]。它的长度为 4。
-
-
## 解法
-
+
### **Python3**
+
```python
@@ -30,6 +30,7 @@
```
### **Java**
+
```java
@@ -37,8 +38,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0100-0199/0128.Longest Consecutive Sequence/README_EN.md b/solution/0100-0199/0128.Longest Consecutive Sequence/README_EN.md
index 02c69fe784e7a..c00319c3b127c 100644
--- a/solution/0100-0199/0128.Longest Consecutive Sequence/README_EN.md
+++ b/solution/0100-0199/0128.Longest Consecutive Sequence/README_EN.md
@@ -3,18 +3,13 @@
[中文文档](/solution/0100-0199/0128.Longest%20Consecutive%20Sequence/README.md)
## Description
-Given an unsorted array of integers, find the length of the longest consecutive elements sequence.
- +Given an unsorted array of integers, find the length of the longest consecutive elements sequence.
Your algorithm should run in O(n) complexity.
- -Example:
- -Input: [100, 4, 200, 1, 3, 2] @@ -25,12 +20,8 @@- - - ## Solutions - ### **Python3** @@ -46,8 +37,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0129.Sum Root to Leaf Numbers/README.md b/solution/0100-0199/0129.Sum Root to Leaf Numbers/README.md index 3b1488ab21695..a0ca8d3e67db9 100644 --- a/solution/0100-0199/0129.Sum Root to Leaf Numbers/README.md +++ b/solution/0100-0199/0129.Sum Root to Leaf Numbers/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0129.Sum%20Root%20to%20Leaf%20Numbers/README_EN.md) ## 题目描述 +
给定一个二叉树,它的每个结点都存放一个 0-9
的数字,每条从根到叶子节点的路径都代表一个数字。
4->0
代表数字 40.
因此,数字总和 = 495 + 491 + 40 = 1026
.
-
-
## 解法
-
+
### **Python3**
+
```python
@@ -55,6 +55,7 @@
```
### **Java**
+
```java
@@ -62,8 +63,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0100-0199/0129.Sum Root to Leaf Numbers/README_EN.md b/solution/0100-0199/0129.Sum Root to Leaf Numbers/README_EN.md
index d1abd44a9bc97..6c3bce87d5295 100644
--- a/solution/0100-0199/0129.Sum Root to Leaf Numbers/README_EN.md
+++ b/solution/0100-0199/0129.Sum Root to Leaf Numbers/README_EN.md
@@ -3,26 +3,17 @@
[中文文档](/solution/0100-0199/0129.Sum%20Root%20to%20Leaf%20Numbers/README.md)
## Description
-Given a binary tree containing digits from 0-9
only, each root-to-leaf path could represent a number.
Given a binary tree containing digits from 0-9
only, each root-to-leaf path could represent a number.
An example is the root-to-leaf path 1->2->3
which represents the number 123
.
Find the total sum of all root-to-leaf numbers.
- -Note: A leaf is a node with no children.
- -Example:
- -Input: [1,2,3] @@ -43,12 +34,8 @@ The root-to-leaf path- -1->3
represents the number13
Therefore, sum = 12 + 13 =25
.
Example 2:
- -Input: [4,9,0,5,1] @@ -75,12 +62,8 @@ The root-to-leaf path- - - ## Solutions - ### **Python3** @@ -96,8 +79,9 @@ Therefore, sum = 495 + 491 + 40 =4->0
represents the number 40. Therefore, sum = 495 + 491 + 40 =1026
.
1026
.
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0100-0199/0130.Surrounded Regions/README.md b/solution/0100-0199/0130.Surrounded Regions/README.md
index abe3491d2e689..96792addb83c6 100644
--- a/solution/0100-0199/0130.Surrounded Regions/README.md
+++ b/solution/0100-0199/0130.Surrounded Regions/README.md
@@ -3,6 +3,7 @@
[English Version](/solution/0100-0199/0130.Surrounded%20Regions/README_EN.md)
## 题目描述
+
给定一个二维的矩阵,包含 'X'
和 'O'
(字母 O)。
被围绕的区间不会存在于边界上,换句话说,任何边界上的 'O'
都不会被填充为 'X'
。 任何不在边界上,或不与边界上的 'O'
相连的 'O'
最终都会被填充为 'X'
。如果两个元素在水平或垂直方向相邻,则称它们是“相连”的。
Given a 2D board containing 'X'
and 'O'
(the letter O), capture all regions surrounded by 'X'
.
Given a 2D board containing 'X'
and 'O'
(the letter O), capture all regions surrounded by 'X'
.
A region is captured by flipping all 'O'
s into 'X'
s in that surrounded region.
Example:
- -X X X X @@ -27,12 +22,8 @@ X O X X- -
After running your function, the board should be:
- -X X X X @@ -45,20 +36,12 @@ X O X X- -
Explanation:
- -Surrounded regions shouldn’t be on the border, which means that any 'O'
on the border of the board are not flipped to 'X'
. Any 'O'
that is not on the border and it is not connected to an 'O'
on the border will be flipped to 'X'
. Two cells are connected if they are adjacent cells connected horizontally or vertically.
给定一个字符串 s,将 s 分割成一些子串,使每个子串都是回文串。
@@ -17,15 +18,14 @@ ["a","a","b"] ] - - ## 解法 - + ### **Python3** + ```python @@ -33,6 +33,7 @@ ``` ### **Java** + ```java @@ -40,8 +41,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0131.Palindrome Partitioning/README_EN.md b/solution/0100-0199/0131.Palindrome Partitioning/README_EN.md index cdaf40438b637..c3fbd5f8eacfd 100644 --- a/solution/0100-0199/0131.Palindrome Partitioning/README_EN.md +++ b/solution/0100-0199/0131.Palindrome Partitioning/README_EN.md @@ -3,18 +3,13 @@ [中文文档](/solution/0100-0199/0131.Palindrome%20Partitioning/README.md) ## Description -Given a string s, partition s such that every substring of the partition is a palindrome.
- +Given a string s, partition s such that every substring of the partition is a palindrome.
Return all possible palindrome partitioning of s.
- -Example:
- -Input: "aab" @@ -31,12 +26,8 @@- - - ## Solutions - ### **Python3** @@ -52,8 +43,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0132.Palindrome Partitioning II/README.md b/solution/0100-0199/0132.Palindrome Partitioning II/README.md index 85fdeba48ed38..e52af7b0395ac 100644 --- a/solution/0100-0199/0132.Palindrome Partitioning II/README.md +++ b/solution/0100-0199/0132.Palindrome Partitioning II/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0132.Palindrome%20Partitioning%20II/README_EN.md) ## 题目描述 +
给定一个字符串 s,将 s 分割成一些子串,使每个子串都是回文串。
@@ -15,15 +16,14 @@ 解释: 进行一次分割就可将 s 分割成 ["aa","b"] 这样两个回文子串。 - - ## 解法 - + ### **Python3** + ```python @@ -31,6 +31,7 @@ ``` ### **Java** + ```java @@ -38,8 +39,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0132.Palindrome Partitioning II/README_EN.md b/solution/0100-0199/0132.Palindrome Partitioning II/README_EN.md index 730206937fd48..9a5e96d1928e5 100644 --- a/solution/0100-0199/0132.Palindrome Partitioning II/README_EN.md +++ b/solution/0100-0199/0132.Palindrome Partitioning II/README_EN.md @@ -3,18 +3,13 @@ [中文文档](/solution/0100-0199/0132.Palindrome%20Partitioning%20II/README.md) ## Description -Given a string s, partition s such that every substring of the partition is a palindrome.
- +Given a string s, partition s such that every substring of the partition is a palindrome.
Return the minimum cuts needed for a palindrome partitioning of s.
- -Example:
- -Input: "aab" @@ -25,12 +20,8 @@- - - ## Solutions - ### **Python3** @@ -46,8 +37,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0133.Clone Graph/README.md b/solution/0100-0199/0133.Clone Graph/README.md index ed9e5432e2857..cc0104f398d23 100644 --- a/solution/0100-0199/0133.Clone Graph/README.md +++ b/solution/0100-0199/0133.Clone Graph/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0133.Clone%20Graph/README_EN.md) ## 题目描述 +
给你无向 连通 图中一个节点的引用,请你返回该图的 深拷贝(克隆)。
@@ -74,15 +75,14 @@Given a reference of a node in a connected undirected graph.
Return a deep copy (clone) of the graph.
@@ -79,11 +80,8 @@ class Node {在一条环路上有 N 个加油站,其中第 i 个加油站有汽油 gas[i]
升。
There are N gas stations along a circular route, where the amount of gas at station i is gas[i]
.
There are N gas stations along a circular route, where the amount of gas at station i is gas[i]
.
You have a car with an unlimited gas tank and it costs cost[i]
of gas to travel from station i to its next station (i+1). You begin the journey with an empty tank at one of the gas stations.
Return the starting gas station's index if you can travel around the circuit once in the clockwise direction, otherwise return -1.
- -Note:
- -Example 1:
- -Input: @@ -67,12 +56,8 @@ Therefore, return 3 as the starting index.- -
Example 2:
- -Input: @@ -103,12 +88,8 @@ Therefore, you can't travel around the circuit once no matter where you star- - - ## Solutions - ### **Python3** @@ -124,8 +105,9 @@ Therefore, you can't travel around the circuit once no matter where you star ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0135.Candy/README.md b/solution/0100-0199/0135.Candy/README.md index 0da185cb0d1e8..4fe98bb6ea2cc 100644 --- a/solution/0100-0199/0135.Candy/README.md +++ b/solution/0100-0199/0135.Candy/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0135.Candy/README_EN.md) ## 题目描述 +
老师想给孩子们分发糖果,有 N 个孩子站成了一条直线,老师会根据每个孩子的表现,预先给他们评分。
@@ -29,15 +30,14 @@ 解释: 你可以分别给这三个孩子分发 1、2、1 颗糖果。 第三个孩子只得到 1 颗糖果,这已满足上述两个条件。 - - ## 解法 - + ### **Python3** + ```python @@ -45,6 +45,7 @@ ``` ### **Java** + ```java @@ -52,8 +53,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0135.Candy/README_EN.md b/solution/0100-0199/0135.Candy/README_EN.md index 951113ed77041..38ab6559be674 100644 --- a/solution/0100-0199/0135.Candy/README_EN.md +++ b/solution/0100-0199/0135.Candy/README_EN.md @@ -3,32 +3,23 @@ [中文文档](/solution/0100-0199/0135.Candy/README.md) ## Description -There are N children standing in a line. Each child is assigned a rating value.
- +There are N children standing in a line. Each child is assigned a rating value.
You are giving candies to these children subjected to the following requirements:
- -What is the minimum candies you must give?
- -Example 1:
- -Input: [1,0,2] @@ -39,12 +30,8 @@- -
Example 2:
- -Input: [1,2,2] @@ -57,12 +44,8 @@- - - ## Solutions - ### **Python3** @@ -78,8 +61,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0136.Single Number/README.md b/solution/0100-0199/0136.Single Number/README.md index d56f9ed935162..db48956a93ae5 100644 --- a/solution/0100-0199/0136.Single Number/README.md +++ b/solution/0100-0199/0136.Single Number/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0136.Single%20Number/README_EN.md) ## 题目描述 +
给定一个非空整数数组,除了某个元素只出现一次以外,其余每个元素均出现两次。找出那个只出现了一次的元素。
@@ -21,9 +22,8 @@输入: [4,1,2,1,2] 输出: 4- - ## 解法 + 异或运算求解。 @@ -33,6 +33,7 @@ ### **Python3** + ```python @@ -45,6 +46,7 @@ class Solution: ``` ### **Java** + ```java @@ -60,8 +62,9 @@ class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0136.Single Number/README_EN.md b/solution/0100-0199/0136.Single Number/README_EN.md index af064b6d6c979..b2d674e9034f3 100644 --- a/solution/0100-0199/0136.Single Number/README_EN.md +++ b/solution/0100-0199/0136.Single Number/README_EN.md @@ -3,22 +3,15 @@ [中文文档](/solution/0100-0199/0136.Single%20Number/README.md) ## Description -
Given a non-empty array of integers, every element appears twice except for one. Find that single one.
- +Given a non-empty 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 implement it without using extra memory?
- -Example 1:
- -Input: [2,2,1] @@ -27,12 +20,8 @@- -
Example 2:
- -Input: [4,1,2,1,2] @@ -41,12 +30,8 @@- - - ## Solutions - ### **Python3** @@ -75,8 +60,9 @@ class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0136.Single Number/Solution.js b/solution/0100-0199/0136.Single Number/Solution.js index 094bc6fcfcb65..35d56f03a1468 100644 --- a/solution/0100-0199/0136.Single Number/Solution.js +++ b/solution/0100-0199/0136.Single Number/Solution.js @@ -1,26 +1,26 @@ -const singleNumber2 = function(nums){ +const singleNumber2 = function (nums) { const map = {}; - for(let i = 0; i < nums.length; i++){ - if(map[nums[i]] === undefined){ + for (let i = 0; i < nums.length; i++) { + if (map[nums[i]] === undefined) { map[nums[i]] = 1; - }else if(map[nums[i]] === 1){ + } else if (map[nums[i]] === 1) { map[nums[i]]++; } } - for(let key in map){ - if(map[key] === 1){ + for (let key in map) { + if (map[key] === 1) { return Number(key); } } -} -const singleNumber = function(nums){ +}; +const singleNumber = function (nums) { //XOR let result = 0; - for(let i = 0; i < nums.length; i++){ + for (let i = 0; i < nums.length; i++) { result = result ^ nums[i]; } return result; //or in es6 //return nums.reduce((result, num) => result ^ num, 0); -} +}; diff --git a/solution/0100-0199/0137.Single Number II/README.md b/solution/0100-0199/0137.Single Number II/README.md index 652039d6e293f..444fd87c2639a 100644 --- a/solution/0100-0199/0137.Single Number II/README.md +++ b/solution/0100-0199/0137.Single Number II/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0137.Single%20Number%20II/README_EN.md) ## 题目描述 +
给定一个非空整数数组,除了某个元素只出现一次以外,其余每个元素均出现了三次。找出那个只出现了一次的元素。
@@ -21,9 +22,8 @@输入: [0,1,0,1,0,1,99] 输出: 99- - ## 解法 + 统计所有数字每个位中 1 出现的次数,对于某个位,1 出现的次数一定是 3 的倍数 +1 或 0。对这个数 %3 得到的结果就是那个出现一次的数字在该位上的值。 @@ -31,6 +31,7 @@ ### **Python3** + ```python @@ -38,6 +39,7 @@ ``` ### **Java** + ```java @@ -63,8 +65,9 @@ class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0137.Single Number II/README_EN.md b/solution/0100-0199/0137.Single Number II/README_EN.md index 958587dfc15c2..78521cf9a9282 100644 --- a/solution/0100-0199/0137.Single Number II/README_EN.md +++ b/solution/0100-0199/0137.Single Number II/README_EN.md @@ -3,22 +3,15 @@ [中文文档](/solution/0100-0199/0137.Single%20Number%20II/README.md) ## Description -
Given a non-empty array of integers, every element appears three times except for one, which appears exactly once. Find that single one.
- +Given a non-empty array of integers, every element appears three times except for one, which appears exactly once. Find that single one.
Note:
- -Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?
- -Example 1:
- -Input: [2,2,3,2] @@ -27,24 +20,16 @@- -
Example 2:
- -Input: [0,1,0,1,0,1,99] Output: 99- - - ## Solutions - ### **Python3** @@ -78,8 +63,9 @@ class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0138.Copy List with Random Pointer/README.md b/solution/0100-0199/0138.Copy List with Random Pointer/README.md index 56cc4d6360715..2a555e7ed20b7 100644 --- a/solution/0100-0199/0138.Copy List with Random Pointer/README.md +++ b/solution/0100-0199/0138.Copy List with Random Pointer/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0138.Copy%20List%20with%20Random%20Pointer/README_EN.md) ## 题目描述 +
给定一个链表,每个节点包含一个额外增加的随机指针,该指针可以指向链表中的任何节点或空节点。
@@ -58,15 +59,14 @@A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null.
Return a deep copy of the list.
@@ -59,11 +60,8 @@给定一个非空字符串 s 和一个包含非空单词列表的字典 wordDict,判定 s 是否可以被空格拆分为一个或多个在字典中出现的单词。
@@ -34,15 +35,14 @@ 输出: false - - ## 解法 - + ### **Python3** + ```python @@ -50,6 +50,7 @@ ``` ### **Java** + ```java @@ -57,8 +58,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0139.Word Break/README_EN.md b/solution/0100-0199/0139.Word Break/README_EN.md index 8a22fab944b13..7e6310f54d2fe 100644 --- a/solution/0100-0199/0139.Word Break/README_EN.md +++ b/solution/0100-0199/0139.Word Break/README_EN.md @@ -3,28 +3,21 @@ [中文文档](/solution/0100-0199/0139.Word%20Break/README.md) ## Description -Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, determine if s can be segmented into a space-separated sequence of one or more dictionary words.
- +Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, determine if s can be segmented into a space-separated sequence of one or more dictionary words.
Note:
- -Example 1:
- -Input: s = "leetcode", wordDict = ["leet", "code"] @@ -35,12 +28,8 @@- -
Example 2:
- -Input: s = "applepenapple", wordDict = ["apple", "pen"] @@ -53,12 +42,8 @@- -
Example 3:
- -Input: s = "catsandog", wordDict = ["cats", "dog", "sand", "and", "cat"] @@ -67,12 +52,8 @@- - - ## Solutions - ### **Python3** @@ -88,8 +69,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0140.Word Break II/README.md b/solution/0100-0199/0140.Word Break II/README.md index c452d47af5a9e..21646391f8ba2 100644 --- a/solution/0100-0199/0140.Word Break II/README.md +++ b/solution/0100-0199/0140.Word Break II/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0140.Word%20Break%20II/README_EN.md) ## 题目描述 +
给定一个非空字符串 s 和一个包含非空单词列表的字典 wordDict,在字符串中增加空格来构建一个句子,使得句子中所有的单词都在词典中。返回所有这些可能的句子。
@@ -48,15 +49,14 @@ wordDict = ["cats", "dog", "sand", "and" [] - - ## 解法 - + ### **Python3** + ```python @@ -64,6 +64,7 @@ wordDict = ["cats", "dog", "sand", "and" ``` ### **Java** + ```java @@ -71,8 +72,9 @@ wordDict = ["cats", "dog", "sand", "and" ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0140.Word Break II/README_EN.md b/solution/0100-0199/0140.Word Break II/README_EN.md index a2387fc4cabd5..b5db5c303f2d5 100644 --- a/solution/0100-0199/0140.Word Break II/README_EN.md +++ b/solution/0100-0199/0140.Word Break II/README_EN.md @@ -3,28 +3,21 @@ [中文文档](/solution/0100-0199/0140.Word%20Break%20II/README.md) ## Description -Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, add spaces in s to construct a sentence where each word is a valid dictionary word. Return all such possible sentences.
- +Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, add spaces in s to construct a sentence where each word is a valid dictionary word. Return all such possible sentences.
Note:
- -Example 1:
- -
Input:
@@ -45,12 +38,8 @@ wordDict = ["cat", "cats", "and", "sand
-
-
Example 2:
- -Input: @@ -75,12 +64,8 @@ wordDict = ["apple", "pen", "applepen", "pine- -
Example 3:
- -Input: @@ -93,12 +78,8 @@ wordDict = ["cats", "dog", "sand", "and" []- - - ## Solutions - ### **Python3** @@ -114,8 +95,9 @@ wordDict = ["cats", "dog", "sand", "and" ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0141.Linked List Cycle/README.md b/solution/0100-0199/0141.Linked List Cycle/README.md index d7a2019a0407e..689a543d57151 100644 --- a/solution/0100-0199/0141.Linked List Cycle/README.md +++ b/solution/0100-0199/0141.Linked List Cycle/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0141.Linked%20List%20Cycle/README_EN.md) ## 题目描述 +
给定一个链表,判断链表中是否有环。
@@ -26,7 +27,6 @@ 解释:链表中有一个环,其尾部连接到第一个节点。 - 示例 3:
@@ -44,19 +44,18 @@你能用 O(1)(即,常量)内存解决此问题吗?
- - ## 解法 + 定义快慢指针 `slow`、`fast`,初始指向 `head`。 快指针每次走两步,慢指针每次走一步,不断循环。当相遇时,说明链表存在环。如果循环结束依然没有相遇,说明链表不存在环。 - ### **Python3** + ```python @@ -77,6 +76,7 @@ class Solution: ``` ### **Java** + ```java @@ -108,8 +108,9 @@ public class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0141.Linked List Cycle/README_EN.md b/solution/0100-0199/0141.Linked List Cycle/README_EN.md index 94f762619328c..71a9efcb7518c 100644 --- a/solution/0100-0199/0141.Linked List Cycle/README_EN.md +++ b/solution/0100-0199/0141.Linked List Cycle/README_EN.md @@ -3,24 +3,17 @@ [中文文档](/solution/0100-0199/0141.Linked%20List%20Cycle/README.md) ## Description -Given a linked list, determine if it has a cycle in it.
- +Given a linked list, determine if it has a cycle in it.
To represent a cycle in the given linked list, we use an integer pos
which represents the position (0-indexed) in the linked list where tail connects to. If pos
is -1
, then there is no cycle in the linked list.
- -
Example 1:
- -Input: head = [3,2,0,-4], pos = 1 @@ -33,18 +26,12 @@
Example 2:
- -Input: head = [1,2], pos = 0 @@ -57,17 +44,12 @@
Example 3:
- -Input: head = [1], pos = -1 @@ -80,27 +62,16 @@
- -
Follow up:
- -Can you solve it using O(1) (i.e. constant) memory?
- - - ## Solutions - ### **Python3** @@ -153,8 +124,9 @@ public class Solution { ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0141.Linked List Cycle/Solution.js b/solution/0100-0199/0141.Linked List Cycle/Solution.js index b2203e08904d7..e8d13b69e8d94 100644 --- a/solution/0100-0199/0141.Linked List Cycle/Solution.js +++ b/solution/0100-0199/0141.Linked List Cycle/Solution.js @@ -10,29 +10,26 @@ * @param {ListNode} head * @return {boolean} */ -var hasCycle = function(head) { - flag = false; - - dfs(head); +var hasCycle = function (head) { + flag = false; - return flag; + dfs(head); + + return flag; }; function dfs(node) { - if (flag) - return; + if (flag) return; - if (node === null) - return; + if (node === null) return; if (node.flag) { flag = true; return; } - if (node.next === null) - return; + if (node.next === null) return; node.flag = true; dfs(node.next); -} \ No newline at end of file +} diff --git a/solution/0100-0199/0142.Linked List Cycle II/README.md b/solution/0100-0199/0142.Linked List Cycle II/README.md index 4fd91c4c7c801..12bc2b2d822d1 100644 --- a/solution/0100-0199/0142.Linked List Cycle II/README.md +++ b/solution/0100-0199/0142.Linked List Cycle II/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0142.Linked%20List%20Cycle%20II/README_EN.md) ## 题目描述 +给定一个链表,返回链表开始入环的第一个节点。 如果链表无环,则返回 null
。
进阶:
你是否可以不用额外空间解决此题?
Given a linked list, return the node where the cycle begins. If there is no cycle, return null
.
To represent a cycle in the given linked list, we use an integer pos
which represents the position (0-indexed) in the linked list where tail connects to. If pos
is -1
, then there is no cycle in the linked list.
Follow-up:
Can you solve it without using extra space?
给定一个单链表 L:L0→L1→…→Ln-1→Ln ,
将其重新排列后变为: L0→Ln→L1→Ln-1→L2→Ln-2→…
给定链表 1->2->3->4->5, 重新排列为 1->5->2->4->3.- - ## 解法 - + ### **Python3** + ```python @@ -33,6 +33,7 @@ ``` ### **Java** + ```java @@ -40,8 +41,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0143.Reorder List/README_EN.md b/solution/0100-0199/0143.Reorder List/README_EN.md index 11025db0f4555..82833ecd51b6a 100644 --- a/solution/0100-0199/0143.Reorder List/README_EN.md +++ b/solution/0100-0199/0143.Reorder List/README_EN.md @@ -3,42 +3,29 @@ [中文文档](/solution/0100-0199/0143.Reorder%20List/README.md) ## Description +
Given a singly linked list L: L0→L1→…→Ln-1→Ln,
reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→…
You may not modify the values in the list's nodes, only nodes itself may be changed.
- -Example 1:
- -Given 1->2->3->4, reorder it to 1->4->2->3.- -
Example 2:
- -Given 1->2->3->4->5, reorder it to 1->5->2->4->3.- - - ## Solutions - ### **Python3** @@ -54,8 +41,9 @@ Given 1->2->3->4->5, reorder it to 1->5->2->4->3. ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0144.Binary Tree Preorder Traversal/README.md b/solution/0100-0199/0144.Binary Tree Preorder Traversal/README.md index 176921b426a63..77ed81d7f5325 100644 --- a/solution/0100-0199/0144.Binary Tree Preorder Traversal/README.md +++ b/solution/0100-0199/0144.Binary Tree Preorder Traversal/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0144.Binary%20Tree%20Preorder%20Traversal/README_EN.md) ## 题目描述 +
给定一个二叉树,返回它的 前序 遍历。
@@ -20,15 +21,14 @@进阶: 递归算法很简单,你可以通过迭代算法完成吗?
- - ## 解法 - + ### **Python3** + ```python @@ -36,6 +36,7 @@ ``` ### **Java** + ```java @@ -43,8 +44,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0144.Binary Tree Preorder Traversal/README_EN.md b/solution/0100-0199/0144.Binary Tree Preorder Traversal/README_EN.md index 96a14ed933aa7..2cf76c191bc96 100644 --- a/solution/0100-0199/0144.Binary Tree Preorder Traversal/README_EN.md +++ b/solution/0100-0199/0144.Binary Tree Preorder Traversal/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/solution/0100-0199/0144.Binary%20Tree%20Preorder%20Traversal/README.md) ## Description -Given a binary tree, return the preorder traversal of its nodes' values.
- +Given a binary tree, return the preorder traversal of its nodes' values.
Example:
- -
Input: [1,null,2,3]
@@ -31,16 +28,10 @@
-
-
Follow up: Recursive solution is trivial, could you do it iteratively?
- - - ## Solutions - ### **Python3** @@ -56,8 +47,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0145.Binary Tree Postorder Traversal/README.md b/solution/0100-0199/0145.Binary Tree Postorder Traversal/README.md index af565cfdb2e76..3d62457bd5272 100644 --- a/solution/0100-0199/0145.Binary Tree Postorder Traversal/README.md +++ b/solution/0100-0199/0145.Binary Tree Postorder Traversal/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0145.Binary%20Tree%20Postorder%20Traversal/README_EN.md) ## 题目描述 +给定一个二叉树,返回它的 后序 遍历。
@@ -19,15 +20,14 @@进阶: 递归算法很简单,你可以通过迭代算法完成吗?
- - ## 解法 - + ### **Python3** + ```python @@ -35,6 +35,7 @@ ``` ### **Java** + ```java @@ -42,8 +43,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0145.Binary Tree Postorder Traversal/README_EN.md b/solution/0100-0199/0145.Binary Tree Postorder Traversal/README_EN.md index 0ebfc7e06a972..1aa49480e34d9 100644 --- a/solution/0100-0199/0145.Binary Tree Postorder Traversal/README_EN.md +++ b/solution/0100-0199/0145.Binary Tree Postorder Traversal/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/solution/0100-0199/0145.Binary%20Tree%20Postorder%20Traversal/README.md) ## Description -Given a binary tree, return the postorder traversal of its nodes' values.
- +Given a binary tree, return the postorder traversal of its nodes' values.
Example:
- -
Input: [1,null,2,3]
@@ -31,16 +28,10 @@
-
-
Follow up: Recursive solution is trivial, could you do it iteratively?
- - - ## Solutions - ### **Python3** @@ -56,8 +47,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0146.Lru Cache/README.md b/solution/0100-0199/0146.Lru Cache/README.md index 9e048805a5fc8..6b6b91a40f423 100644 --- a/solution/0100-0199/0146.Lru Cache/README.md +++ b/solution/0100-0199/0146.Lru Cache/README.md @@ -1,8 +1,9 @@ -# [146. LRU缓存机制](https://leetcode-cn.com/problems/lru-cache) +# [146. LRU 缓存机制](https://leetcode-cn.com/problems/lru-cache) [English Version](/solution/0100-0199/0146.Lru%20Cache/README_EN.md) ## 题目描述 +运用你所掌握的数据结构,设计和实现一个 LRU (最近最少使用) 缓存机制。它应该支持以下操作: 获取数据 get
和 写入数据 put
。
Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get
and put
.
Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get
and put
.
get(key)
- Get the value (will always be positive) of the key if the key exists in the cache, otherwise return -1.
put(key, value)
- Set or insert the value if the key is not already present. When the cache reached its capacity, it should invalidate the least recently used item before inserting a new item.
The cache is initialized with a positive capacity.
- -Follow up:
Could you do both operations in O(1) time complexity?
Example:
- -LRUCache cache = new LRUCache( 2 /* capacity */ ); @@ -53,16 +44,10 @@ cache.get(4); // returns 4- -
- - - ## Solutions - ### **Python3** @@ -78,8 +63,9 @@ cache.get(4); // returns 4 ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0147.Insertion Sort List/README.md b/solution/0100-0199/0147.Insertion Sort List/README.md index 8f17e5bf0d67e..f89c6bf02283c 100644 --- a/solution/0100-0199/0147.Insertion Sort List/README.md +++ b/solution/0100-0199/0147.Insertion Sort List/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0147.Insertion%20Sort%20List/README_EN.md) ## 题目描述 +
对链表进行插入排序。
@@ -34,15 +35,14 @@ 输出: -1->0->3->4->5 - - ## 解法 - + ### **Python3** + ```python @@ -50,6 +50,7 @@ ``` ### **Java** + ```java @@ -57,8 +58,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0147.Insertion Sort List/README_EN.md b/solution/0100-0199/0147.Insertion Sort List/README_EN.md index d64447373d89a..50f0f542de0af 100644 --- a/solution/0100-0199/0147.Insertion Sort List/README_EN.md +++ b/solution/0100-0199/0147.Insertion Sort List/README_EN.md @@ -3,16 +3,13 @@ [中文文档](/solution/0100-0199/0147.Insertion%20Sort%20List/README.md) ## Description -Sort a linked list using insertion sort.
- +Sort a linked list using insertion sort.
A graphical example of insertion sort. The partial sorted list (black) initially contains only the first element in the list.
@@ -21,36 +18,26 @@ With each iteration one element (red) is removed from the input data and inserte
Algorithm of Insertion Sort:
- -
Example 1:
Input: 4->2->1->3 @@ -59,12 +46,8 @@ With each iteration one element (red) is removed from the input data and inserte- -
Example 2:
- -Input: -1->5->3->4->0 @@ -73,12 +56,8 @@ With each iteration one element (red) is removed from the input data and inserte- - - ## Solutions - ### **Python3** @@ -94,8 +73,9 @@ With each iteration one element (red) is removed from the input data and inserte ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0148.Sort List/README.md b/solution/0100-0199/0148.Sort List/README.md index 273f94ffc9eb0..4a0f810efe14c 100644 --- a/solution/0100-0199/0148.Sort List/README.md +++ b/solution/0100-0199/0148.Sort List/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0148.Sort%20List/README_EN.md) ## 题目描述 +
在 O(n log n) 时间复杂度和常数级空间复杂度下,对链表进行排序。
@@ -17,15 +18,14 @@输入: -1->5->3->4->0 输出: -1->0->3->4->5- - ## 解法 - + ### **Python3** + ```python @@ -33,6 +33,7 @@ ``` ### **Java** + ```java @@ -40,8 +41,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0148.Sort List/README_EN.md b/solution/0100-0199/0148.Sort List/README_EN.md index f8c4cb1401e32..8630904e1c58d 100644 --- a/solution/0100-0199/0148.Sort List/README_EN.md +++ b/solution/0100-0199/0148.Sort List/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/solution/0100-0199/0148.Sort%20List/README.md) ## Description -
Sort a linked list in O(n log n) time using constant space complexity.
- +Sort a linked list in O(n log n) time using constant space complexity.
Example 1:
- -Input: 4->2->1->3 @@ -19,24 +16,16 @@- -
Example 2:
- -Input: -1->5->3->4->0 Output: -1->0->3->4->5- - - ## Solutions - ### **Python3** @@ -52,8 +41,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0149.Max Points on a Line/README.md b/solution/0100-0199/0149.Max Points on a Line/README.md index ce607accddbaf..22c75d33b7c4e 100644 --- a/solution/0100-0199/0149.Max Points on a Line/README.md +++ b/solution/0100-0199/0149.Max Points on a Line/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0149.Max%20Points%20on%20a%20Line/README_EN.md) ## 题目描述 +
给定一个二维平面,平面上有 n 个点,求最多有多少个点在同一条直线上。
@@ -34,15 +35,14 @@ +-------------------> 0 1 2 3 4 5 6 - - ## 解法 - + ### **Python3** + ```python @@ -50,6 +50,7 @@ ``` ### **Java** + ```java @@ -57,8 +58,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0149.Max Points on a Line/README_EN.md b/solution/0100-0199/0149.Max Points on a Line/README_EN.md index 75101c4a67381..99ec40316dc1a 100644 --- a/solution/0100-0199/0149.Max Points on a Line/README_EN.md +++ b/solution/0100-0199/0149.Max Points on a Line/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/solution/0100-0199/0149.Max%20Points%20on%20a%20Line/README.md) ## Description -Given n points on a 2D plane, find the maximum number of points that lie on the same straight line.
- +Given n points on a 2D plane, find the maximum number of points that lie on the same straight line.
Example 1:
- -Input: [[1,1],[2,2],[3,3]] @@ -35,12 +32,8 @@- -
Example 2:
- -Input: [[1,1],[3,2],[5,3],[4,1],[2,3],[1,4]] @@ -67,16 +60,10 @@- -
NOTE: input types have been changed on April 15, 2019. Please reset to default code definition to get new method signature.
- - - ## Solutions - ### **Python3** @@ -92,8 +79,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0150.Evaluate Reverse Polish Notation/README.md b/solution/0100-0199/0150.Evaluate Reverse Polish Notation/README.md index 5d7fa91102ff5..e9191e42477a4 100644 --- a/solution/0100-0199/0150.Evaluate Reverse Polish Notation/README.md +++ b/solution/0100-0199/0150.Evaluate Reverse Polish Notation/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0150.Evaluate%20Reverse%20Polish%20Notation/README_EN.md) ## 题目描述 +根据逆波兰表示法,求表达式的值。
@@ -42,15 +43,14 @@ = 17 + 5 = 22 - - ## 解法 - + ### **Python3** + ```python @@ -58,6 +58,7 @@ ``` ### **Java** + ```java @@ -65,8 +66,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0150.Evaluate Reverse Polish Notation/README_EN.md b/solution/0100-0199/0150.Evaluate Reverse Polish Notation/README_EN.md index 99058b99f0352..0e7223b2d8f0e 100644 --- a/solution/0100-0199/0150.Evaluate Reverse Polish Notation/README_EN.md +++ b/solution/0100-0199/0150.Evaluate Reverse Polish Notation/README_EN.md @@ -3,32 +3,23 @@ [中文文档](/solution/0100-0199/0150.Evaluate%20Reverse%20Polish%20Notation/README.md) ## Description -Evaluate the value of an arithmetic expression in Reverse Polish Notation.
- +Evaluate the value of an arithmetic expression in Reverse Polish Notation.
Valid operators are +
, -
, *
, /
. Each operand may be an integer or another expression.
Note:
- -Example 1:
- -Input: ["2", "1", "+", "3", "*"] @@ -39,12 +30,8 @@- -
Example 2:
- -Input: ["4", "13", "5", "/", "+"] @@ -55,12 +42,8 @@- -
Example 3:
- -Input: ["10", "6", "9", "3", "+", "-11", "*", "/", "*", "17", "+", "5", "+"] @@ -85,12 +68,8 @@- - - ## Solutions - ### **Python3** @@ -106,8 +85,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0151.Reverse Words in a String/README.md b/solution/0100-0199/0151.Reverse Words in a String/README.md index c03768b73732d..4f03f03f9a304 100644 --- a/solution/0100-0199/0151.Reverse Words in a String/README.md +++ b/solution/0100-0199/0151.Reverse Words in a String/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0151.Reverse%20Words%20in%20a%20String/README_EN.md) ## 题目描述 +
给定一个字符串,逐个翻转字符串中的每个单词。
@@ -44,15 +45,14 @@请选用 C 语言的用户尝试使用 O(1) 额外空间复杂度的原地解法。
- - ## 解法 - + ### **Python3** + ```python @@ -60,6 +60,7 @@ ``` ### **Java** + ```java @@ -67,8 +68,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0151.Reverse Words in a String/README_EN.md b/solution/0100-0199/0151.Reverse Words in a String/README_EN.md index 91aa38be326ce..d53d7a76ab067 100644 --- a/solution/0100-0199/0151.Reverse Words in a String/README_EN.md +++ b/solution/0100-0199/0151.Reverse Words in a String/README_EN.md @@ -3,18 +3,13 @@ [中文文档](/solution/0100-0199/0151.Reverse%20Words%20in%20a%20String/README.md) ## Description -Given an input string, reverse the string word by word.
- +Given an input string, reverse the string word by word.
- -
Example 1:
- -
Input: "the sky is blue
"
@@ -23,12 +18,8 @@
-
-
Example 2:
- -Input: " hello world! " @@ -39,12 +30,8 @@- -
Example 3:
- -Input: "a good example" @@ -55,42 +42,28 @@- -
- -
Note:
- -- -
Follow up:
- -For C programmers, try to solve it in-place in O(1) extra space.
- ## Solutions - ### **Python3** @@ -106,8 +79,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0152.Maximum Product Subarray/README.md b/solution/0100-0199/0152.Maximum Product Subarray/README.md index 3385b68ba2eda..437cdb312c7b5 100644 --- a/solution/0100-0199/0152.Maximum Product Subarray/README.md +++ b/solution/0100-0199/0152.Maximum Product Subarray/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0152.Maximum%20Product%20Subarray/README_EN.md) ## 题目描述 +给定一个整数数组 nums
,找出一个序列中乘积最大的连续子序列(该序列至少包含一个数)。
Given an integer array nums
, find the contiguous subarray within an array (containing at least one number) which has the largest product.
Given an integer array nums
, find the contiguous subarray within an array (containing at least one number) which has the largest product.
Example 1:
- -Input: [2,3,-2,4] @@ -21,12 +18,8 @@- -
Example 2:
- -Input: [-2,0,-1] @@ -35,12 +28,8 @@ Explanation: The result cannot be 2, because [-2,-1] is not a subarray.- - - ## Solutions - ### **Python3** @@ -56,8 +45,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0153.Find Minimum in Rotated Sorted Array/README.md b/solution/0100-0199/0153.Find Minimum in Rotated Sorted Array/README.md index 7d8f658bb546e..4222a73be2634 100644 --- a/solution/0100-0199/0153.Find Minimum in Rotated Sorted Array/README.md +++ b/solution/0100-0199/0153.Find Minimum in Rotated Sorted Array/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0153.Find%20Minimum%20in%20Rotated%20Sorted%20Array/README_EN.md) ## 题目描述 +
假设按照升序排序的数组在预先未知的某个点上进行了旋转。
@@ -22,15 +23,14 @@输入: [4,5,6,7,0,1,2] 输出: 0- - ## 解法 - + ### **Python3** + ```python @@ -38,6 +38,7 @@ ``` ### **Java** + ```java @@ -45,8 +46,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0153.Find Minimum in Rotated Sorted Array/README_EN.md b/solution/0100-0199/0153.Find Minimum in Rotated Sorted Array/README_EN.md index 9b436f7a24d88..2b0bd455c1c36 100644 --- a/solution/0100-0199/0153.Find Minimum in Rotated Sorted Array/README_EN.md +++ b/solution/0100-0199/0153.Find Minimum in Rotated Sorted Array/README_EN.md @@ -3,26 +3,17 @@ [中文文档](/solution/0100-0199/0153.Find%20Minimum%20in%20Rotated%20Sorted%20Array/README.md) ## Description -
Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.
- +Suppose an array sorted in ascending order 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 minimum element.
- -You may assume no duplicate exists in the array.
- -Example 1:
- -Input: [3,4,5,1,2] @@ -31,12 +22,8 @@- -
Example 2:
- -Input: [4,5,6,7,0,1,2] @@ -45,12 +32,8 @@- - - ## Solutions - ### **Python3** @@ -66,8 +49,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0154.Find Minimum in Rotated Sorted Array II/README.md b/solution/0100-0199/0154.Find Minimum in Rotated Sorted Array II/README.md index 0bcc0da4aa076..b829a8cb0620a 100644 --- a/solution/0100-0199/0154.Find Minimum in Rotated Sorted Array II/README.md +++ b/solution/0100-0199/0154.Find Minimum in Rotated Sorted Array II/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0154.Find%20Minimum%20in%20Rotated%20Sorted%20Array%20II/README_EN.md) ## 题目描述 +
假设按照升序排序的数组在预先未知的某个点上进行了旋转。
@@ -29,15 +30,14 @@Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.
- +Suppose an array sorted in ascending order 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 minimum element.
- -The array may contain duplicates.
- -Example 1:
- -Input: [1,3,5] Output: 1- -
Example 2:
- -Input: [2,2,2,0,1] Output: 0- -
Note:
- -设计一个支持 push,pop,top 操作,并能在常数时间内检索到最小元素的栈。
@@ -25,15 +26,14 @@ minStack.top(); --> 返回 0. minStack.getMin(); --> 返回 -2. - - ## 解法 - + ### **Python3** + ```python @@ -41,6 +41,7 @@ minStack.getMin(); --> 返回 -2. ``` ### **Java** + ```java @@ -48,8 +49,9 @@ minStack.getMin(); --> 返回 -2. ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0155.Min Stack/README_EN.md b/solution/0100-0199/0155.Min Stack/README_EN.md index 884b6eb3e9b14..82d21e247b15a 100644 --- a/solution/0100-0199/0155.Min Stack/README_EN.md +++ b/solution/0100-0199/0155.Min Stack/README_EN.md @@ -3,32 +3,25 @@ [中文文档](/solution/0100-0199/0155.Min%20Stack/README.md) ## Description -Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.
- +Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.
- -
Example:
- -MinStack minStack = new MinStack(); @@ -49,16 +42,10 @@ minStack.getMin(); --> Returns -2.- -
- - - ## Solutions - ### **Python3** @@ -74,8 +61,9 @@ minStack.getMin(); --> Returns -2. ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0155.Min Stack/Solution.js b/solution/0100-0199/0155.Min Stack/Solution.js index 6eeb33e680fc0..4c285f515456d 100644 --- a/solution/0100-0199/0155.Min Stack/Solution.js +++ b/solution/0100-0199/0155.Min Stack/Solution.js @@ -1,62 +1,62 @@ /** * initialize your data structure here. */ -const MinStack = function() { +const MinStack = function () { this.arr = []; - this.help = []; + this.help = []; }; -/** +/** * @param {number} x * @return {void} */ -MinStack.prototype.push = function(x) { - this.arr.push(x); - if(this.help.length === 0){ - this.help.push(0); - }else{ - let min = this.getMin(); - if(x < min){ - this.help.push(this.arr.length-1); - } +MinStack.prototype.push = function (x) { + this.arr.push(x); + if (this.help.length === 0) { + this.help.push(0); + } else { + let min = this.getMin(); + if (x < min) { + this.help.push(this.arr.length - 1); } + } }; /** * @return {void} */ -MinStack.prototype.pop = function() { - if(this.arr.length === 0){ - throw new Error('???'); - } - if(this.arr.length - 1 === this.help[this.help.length - 1]){ - this.help.pop(); - } - this.arr.pop(); +MinStack.prototype.pop = function () { + if (this.arr.length === 0) { + throw new Error("???"); + } + if (this.arr.length - 1 === this.help[this.help.length - 1]) { + this.help.pop(); + } + this.arr.pop(); }; /** * @return {number} */ -MinStack.prototype.top = function() { - return this.arr[this.arr.length-1]; +MinStack.prototype.top = function () { + return this.arr[this.arr.length - 1]; }; /** * @return {number} */ -MinStack.prototype.getMin = function() { - if(this.arr.length === 0){ - throw new Error("???"); - } - return this.arr[this.help[this.help.length-1]]; +MinStack.prototype.getMin = function () { + if (this.arr.length === 0) { + throw new Error("???"); + } + return this.arr[this.help[this.help.length - 1]]; }; -/** +/** * Your MinStack object will be instantiated and called as such: * var obj = Object.create(MinStack).createNew() * obj.push(x) * obj.pop() * var param_3 = obj.top() * var param_4 = obj.getMin() - */ \ No newline at end of file + */ diff --git a/solution/0100-0199/0156.Binary Tree Upside Down/README.md b/solution/0100-0199/0156.Binary Tree Upside Down/README.md index 3c6bbf66c38ca..a45ca3d3cc82d 100644 --- a/solution/0100-0199/0156.Binary Tree Upside Down/README.md +++ b/solution/0100-0199/0156.Binary Tree Upside Down/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0156.Binary%20Tree%20Upside%20Down/README_EN.md) ## 题目描述 +
给定一个二叉树,其中所有的右节点要么是具有兄弟节点(拥有相同父节点的左节点)的叶节点,要么为空,将此二叉树上下翻转并将它变成一棵树, 原来的右节点将转换成左叶节点。返回新的根。
@@ -44,15 +45,14 @@上面的二叉树则被序列化为 [1,2,3,#,#,4,#,#,5]
.
Given a binary tree where all the right nodes are either leaf nodes with a sibling (a left node that shares the same parent node) or empty, flip it upside down and turn it into a tree where the original right nodes turned into left leaf nodes. Return the new root.
Example:
@@ -45,11 +46,8 @@The above binary tree is serialized as [1,2,3,#,#,4,#,#,5]
.
给你一个文件,并且该文件只能通过给定的 read4
方法来读取,请实现一个方法使其能够读取 n 个字符。
buf
保证有足够的空间存下 n 个字符。 Given a file and assume that you can only read the file using a given method read4
, implement a method to read n characters.
@@ -97,11 +98,8 @@ Note: buf[] is destination not source, you will need to write the results to buf
buf
, is guaranteed to have enough space for storing n characters.给你一个文件,并且该文件只能通过给定的 read4
方法来读取,请实现一个方法使其能够读取 n 个字符。注意:你的 read
方法可能会被调用多次。
read
函数使用的是同一个 buf
。Given a file and assume that you can only read the file using a given method read4
, implement a method read
to read n characters. Your method read
may be called multiple times.
@@ -87,11 +88,8 @@ sol.read(buf, 1); // We have reached the end of file, no more characters can be
buf
is called by read
.给定一个字符串 s ,找出 至多 包含两个不同字符的最长子串 t ,并返回该子串的长度。
@@ -20,15 +21,14 @@ 解释: t 是 "aabbb",长度为5。 - - ## 解法 - + ### **Python3** + ```python @@ -36,6 +36,7 @@ ``` ### **Java** + ```java @@ -43,8 +44,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0159.Longest Substring with At Most Two Distinct Characters/README_EN.md b/solution/0100-0199/0159.Longest Substring with At Most Two Distinct Characters/README_EN.md index a29d4f8877a91..c08dc0db6f62c 100644 --- a/solution/0100-0199/0159.Longest Substring with At Most Two Distinct Characters/README_EN.md +++ b/solution/0100-0199/0159.Longest Substring with At Most Two Distinct Characters/README_EN.md @@ -3,6 +3,7 @@ [中文文档](/solution/0100-0199/0159.Longest%20Substring%20with%20At%20Most%20Two%20Distinct%20Characters/README.md) ## Description +Given a string s , find the length of the longest substring t that contains at most 2 distinct characters.
Example 1:
@@ -21,11 +22,8 @@ Explanation: t is "aabbb" which its length is 5. - - ## Solutions - ### **Python3** @@ -41,8 +39,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0160.Intersection of Two Linked Lists/README.md b/solution/0100-0199/0160.Intersection of Two Linked Lists/README.md index 8b81ac821a1fc..e296ff43193d7 100644 --- a/solution/0100-0199/0160.Intersection of Two Linked Lists/README.md +++ b/solution/0100-0199/0160.Intersection of Two Linked Lists/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0160.Intersection%20of%20Two%20Linked%20Lists/README_EN.md) ## 题目描述 +编写一个程序,找到两个单链表相交的起始节点。
@@ -57,15 +58,14 @@Write a program to find the node at which the intersection of two singly linked lists begins.
- +Write a program to find the node at which the intersection of two singly linked lists begins.
For example, the following two linked lists:
 - -begin to intersect at node c1.
- -- -
Example 1:
 @@ -33,12 +26,8 @@ Input Explanation: The intersected node's value is 8 (note that this must not be 0 if the two lists intersect). From the head of A, it reads as [4,1,8,4,5]. From the head of B, it reads as [5,0,1,8,4,5]. There are 2 nodes before the intersected node in A; There are 3 nodes before the intersected node in B. - -- -
Example 2:
 @@ -53,12 +42,8 @@ - -- -
Example 3:
 @@ -75,16 +60,10 @@ - -- -
Notes:
- -null
.给定两个字符串 s 和 t,判断他们的编辑距离是否为 1。
@@ -35,15 +36,14 @@ 输出: true 解释: 可以将字符串 s 中的 '0' 替换为 '1' 来得到 t。 - - ## 解法 - + ### **Python3** + ```python @@ -51,6 +51,7 @@ ``` ### **Java** + ```java @@ -58,8 +59,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0161.One Edit Distance/README_EN.md b/solution/0100-0199/0161.One Edit Distance/README_EN.md index 18766f11cbae1..3a1f8c60ae2c8 100644 --- a/solution/0100-0199/0161.One Edit Distance/README_EN.md +++ b/solution/0100-0199/0161.One Edit Distance/README_EN.md @@ -3,6 +3,7 @@ [中文文档](/solution/0100-0199/0161.One%20Edit%20Distance/README.md) ## Description +Given two strings s and t, determine if they are both one edit distance apart.
Note:
@@ -37,11 +38,8 @@ Output: true Explanation: We can replace '0' with '1' to get t. - - ## Solutions - ### **Python3** @@ -57,8 +55,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0162.Find Peak Element/README.md b/solution/0100-0199/0162.Find Peak Element/README.md index 96054d3f4c26e..dbc2a35c61950 100644 --- a/solution/0100-0199/0162.Find Peak Element/README.md +++ b/solution/0100-0199/0162.Find Peak Element/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0162.Find%20Peak%20Element/README_EN.md) ## 题目描述 +峰值元素是指其值大于左右相邻值的元素。
@@ -30,15 +31,14 @@你的解法应该是 O(logN) 时间复杂度的。
- - ## 解法 - + ### **Python3** + ```python @@ -46,6 +46,7 @@ ``` ### **Java** + ```java @@ -53,8 +54,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0162.Find Peak Element/README_EN.md b/solution/0100-0199/0162.Find Peak Element/README_EN.md index 063fd7fb35953..af3c34a0561b8 100644 --- a/solution/0100-0199/0162.Find Peak Element/README_EN.md +++ b/solution/0100-0199/0162.Find Peak Element/README_EN.md @@ -3,26 +3,17 @@ [中文文档](/solution/0100-0199/0162.Find%20Peak%20Element/README.md) ## Description -A peak element is an element that is greater than its neighbors.
- +A peak element is an element that is greater than its neighbors.
Given an input array nums
, where nums[i] ≠ nums[i+1]
, find a peak element and return its index.
The array may contain multiple peaks, in that case return the index to any one of the peaks is fine.
- -You may imagine that nums[-1] = nums[n] = -∞
.
Example 1:
- -
Input: nums = [1,2,3,1]
@@ -31,12 +22,8 @@
Explanation: 3 is a peak element and your function should return the index number 2.
-
-
Example 2:
- -
Input: nums = [
1,2,1,3,5,6,4]
@@ -49,20 +36,12 @@
-
-
Note:
- -Your solution should be in logarithmic complexity.
- - - ## Solutions - ### **Python3** @@ -78,8 +57,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0163.Missing Ranges/README.md b/solution/0100-0199/0163.Missing Ranges/README.md index 9cef25d7a57cc..b405ba8357e0e 100644 --- a/solution/0100-0199/0163.Missing Ranges/README.md +++ b/solution/0100-0199/0163.Missing Ranges/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0163.Missing%20Ranges/README_EN.md) ## 题目描述 +给定一个排序的整数数组 nums ,其中元素的范围在 闭区间 [lower, upper] 当中,返回不包含在数组中的缺失区间。
@@ -12,15 +13,14 @@ 输出:["2", "4->49", "51->74", "76->99"]
-
-
## 解法
-
+
### **Python3**
+
```python
@@ -28,6 +28,7 @@
```
### **Java**
+
```java
@@ -35,8 +36,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0100-0199/0163.Missing Ranges/README_EN.md b/solution/0100-0199/0163.Missing Ranges/README_EN.md
index ebab1bfdc1c99..6aa7c1351751c 100644
--- a/solution/0100-0199/0163.Missing Ranges/README_EN.md
+++ b/solution/0100-0199/0163.Missing Ranges/README_EN.md
@@ -3,6 +3,7 @@
[中文文档](/solution/0100-0199/0163.Missing%20Ranges/README.md)
## Description
+
Given a sorted integer array nums, where the range of elements are in the inclusive range [lower, upper], return its missing ranges.
Example:
@@ -12,11 +13,8 @@ Output:["2", "4->49", "51->74", "76->99"]
-
-
## Solutions
-
### **Python3**
@@ -32,8 +30,9 @@
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0100-0199/0164.Maximum Gap/README.md b/solution/0100-0199/0164.Maximum Gap/README.md
index dedde8c673694..32fb75af6aa80 100644
--- a/solution/0100-0199/0164.Maximum Gap/README.md
+++ b/solution/0100-0199/0164.Maximum Gap/README.md
@@ -3,6 +3,7 @@
[English Version](/solution/0100-0199/0164.Maximum%20Gap/README_EN.md)
## 题目描述
+
给定一个无序的数组,找出数组在排序之后,相邻元素之间最大的差值。
@@ -27,15 +28,14 @@Given an unsorted array, find the maximum difference between the successive elements in its sorted form.
- +Given an unsorted array, find the maximum difference between the successive elements in its sorted form.
Return 0 if the array contains less than 2 elements.
- -Example 1:
- -Input: [3,6,9,1] @@ -25,12 +20,8 @@ (3,6) or (6,9) has the maximum difference 3.- -
Example 2:
- -Input: [10] @@ -39,26 +30,18 @@ Explanation: The array contains less than 2 elements, therefore return 0.- -
Note:
- -比较两个版本号 version1 和 version2。
如果 version1 > version2
返回 1
,如果 version1 < version2
返回 -1
, 除此之外返回 0
。
Compare two version numbers version1 and version2.
If version1 > version2
return 1;
if version1 < version2
return -1;
otherwise return 0
.
You may assume that the version strings are non-empty and contain only digits and the .
character.
The .
character does not represent a decimal point and is used to separate number sequences.
version1 > version2
return 1;
&
You may assume the default revision number for each level of a version number to be 0
. For example, version number 3.4
has a revision number of 3
and 4
for its first and second level revision number. Its third and fourth level revision number are both 0
.
- -
Example 1:
@@ -31,8 +26,6 @@ If- -version1 > version2
return1;
& Output: -1
Example 2:
@@ -41,8 +34,6 @@ If- -version1 > version2
return1;
& Output: 1
Example 3:
@@ -51,8 +42,6 @@ If- -version1 > version2
return1;
& Output: -1
Example 4:
@@ -63,8 +52,6 @@ If- -version1 > version2
return1;
& Explanation: Ignoring leading zeroes, both “01” and “001" represent the same number “1”
Example 5:
@@ -75,12 +62,8 @@ If- -version1 > version2
return1;
& Explanation: The first version number does not have a third level revision number, which means its third level revision number is default to "0"
- -
Note:
version1 > version2
return 1;
&
version1 > version2
return 1;
&
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0100-0199/0166.Fraction to Recurring Decimal/README.md b/solution/0100-0199/0166.Fraction to Recurring Decimal/README.md
index 96dfc475b2a59..699aceb90abe2 100644
--- a/solution/0100-0199/0166.Fraction to Recurring Decimal/README.md
+++ b/solution/0100-0199/0166.Fraction to Recurring Decimal/README.md
@@ -3,6 +3,7 @@
[English Version](/solution/0100-0199/0166.Fraction%20to%20Recurring%20Decimal/README_EN.md)
## 题目描述
+
给定两个整数,分别表示分数的分子 numerator 和分母 denominator,以字符串形式返回小数。
@@ -25,15 +26,14 @@ 输出: "0.(6)" - - ## 解法 - + ### **Python3** + ```python @@ -41,6 +41,7 @@ ``` ### **Java** + ```java @@ -48,8 +49,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0166.Fraction to Recurring Decimal/README_EN.md b/solution/0100-0199/0166.Fraction to Recurring Decimal/README_EN.md index ea42108b023e1..89ea0c1fc53fa 100644 --- a/solution/0100-0199/0166.Fraction to Recurring Decimal/README_EN.md +++ b/solution/0100-0199/0166.Fraction to Recurring Decimal/README_EN.md @@ -3,18 +3,13 @@ [中文文档](/solution/0100-0199/0166.Fraction%20to%20Recurring%20Decimal/README.md) ## Description -Given two integers representing the numerator and denominator of a fraction, return the fraction in string format.
- +Given two integers representing the numerator and denominator of a fraction, return the fraction in string format.
If the fractional part is repeating, enclose the repeating part in parentheses.
- -Example 1:
- -Input: numerator = 1, denominator = 2 @@ -23,24 +18,16 @@- -
Example 2:
- -Input: numerator = 2, denominator = 1 Output: "2"- -
Example 3:
- -Input: numerator = 2, denominator = 3 @@ -49,12 +36,8 @@- - - ## Solutions - ### **Python3** @@ -70,8 +53,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0167.Two Sum II - Input array is sorted/README.md b/solution/0100-0199/0167.Two Sum II - Input array is sorted/README.md index 8786fdc0aef66..02bab717e57b5 100644 --- a/solution/0100-0199/0167.Two Sum II - Input array is sorted/README.md +++ b/solution/0100-0199/0167.Two Sum II - Input array is sorted/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0167.Two%20Sum%20II%20-%20Input%20array%20is%20sorted/README_EN.md) ## 题目描述 +
给定一个已按照升序排列 的有序数组,找到两个数使得它们相加之和等于目标数。
@@ -21,15 +22,14 @@ 输出: [1,2] 解释: 2 与 7 之和等于目标数 9 。因此 index1 = 1, index2 = 2 。 - - ## 解法 - + ### **Python3** + ```python @@ -37,6 +37,7 @@ ``` ### **Java** + ```java @@ -44,8 +45,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0167.Two Sum II - Input array is sorted/README_EN.md b/solution/0100-0199/0167.Two Sum II - Input array is sorted/README_EN.md index 33d337e94e60a..93e10121e9e9d 100644 --- a/solution/0100-0199/0167.Two Sum II - Input array is sorted/README_EN.md +++ b/solution/0100-0199/0167.Two Sum II - Input array is sorted/README_EN.md @@ -3,32 +3,23 @@ [中文文档](/solution/0100-0199/0167.Two%20Sum%20II%20-%20Input%20array%20is%20sorted/README.md) ## Description -Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number.
- +Given an array of integers that is already sorted in ascending order, 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 index1 must be less than index2.
- -Note:
- -Example:
- -Input: numbers = [2,7,11,15], target = 9 @@ -37,12 +28,8 @@ Explanation: The sum of 2 and 7 is 9. Therefore index1 = 1, index2 = 2.- - - ## Solutions - ### **Python3** @@ -58,8 +45,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0168.Excel Sheet Column Title/README.md b/solution/0100-0199/0168.Excel Sheet Column Title/README.md index a3c596748e4ab..e0bdcb12f4d74 100644 --- a/solution/0100-0199/0168.Excel Sheet Column Title/README.md +++ b/solution/0100-0199/0168.Excel Sheet Column Title/README.md @@ -1,8 +1,9 @@ -# [168. Excel表列名称](https://leetcode-cn.com/problems/excel-sheet-column-title) +# [168. Excel 表列名称](https://leetcode-cn.com/problems/excel-sheet-column-title) [English Version](/solution/0100-0199/0168.Excel%20Sheet%20Column%20Title/README_EN.md) ## 题目描述 +
给定一个正整数,返回它在 Excel 表中相对应的列名称。
@@ -36,15 +37,14 @@ 输出: "ZY" - - ## 解法 - + ### **Python3** + ```python @@ -52,6 +52,7 @@ ``` ### **Java** + ```java @@ -59,8 +60,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0168.Excel Sheet Column Title/README_EN.md b/solution/0100-0199/0168.Excel Sheet Column Title/README_EN.md index 5d2ed514ed4e9..852b873e441b9 100644 --- a/solution/0100-0199/0168.Excel Sheet Column Title/README_EN.md +++ b/solution/0100-0199/0168.Excel Sheet Column Title/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/solution/0100-0199/0168.Excel%20Sheet%20Column%20Title/README.md) ## Description -Given a positive integer, return its corresponding column title as appear in an Excel sheet.
- +Given a positive integer, return its corresponding column title as appear in an Excel sheet.
For example:
- -1 -> A @@ -31,12 +28,8 @@- -
Example 1:
- -Input: 1 @@ -45,12 +38,8 @@- -
Example 2:
- -Input: 28 @@ -59,12 +48,8 @@- -
Example 3:
- -Input: 701 @@ -73,10 +58,8 @@- ## Solutions - ### **Python3** @@ -92,8 +75,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0169.Majority Element/README.md b/solution/0100-0199/0169.Majority Element/README.md index 33de71d6dea40..e957b1bf9c1a3 100644 --- a/solution/0100-0199/0169.Majority Element/README.md +++ b/solution/0100-0199/0169.Majority Element/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0169.Majority%20Element/README_EN.md) ## 题目描述 +
给定一个大小为 n 的数组,找到其中的多数元素。多数元素是指在数组中出现次数大于 ⌊ n/2 ⌋
的元素。
Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋
times.
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 the majority element always exist in the array.
- -Example 1:
- -Input: [3,2,3] Output: 3- -
Example 2:
- -Input: [2,2,1,1,1,2,2] @@ -35,12 +26,8 @@- - - ## Solutions - ### **Python3** @@ -56,8 +43,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0170.Two Sum III - Data structure design/README.md b/solution/0100-0199/0170.Two Sum III - Data structure design/README.md index 7da2de65848b7..346dea31880bb 100644 --- a/solution/0100-0199/0170.Two Sum III - Data structure design/README.md +++ b/solution/0100-0199/0170.Two Sum III - Data structure design/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0170.Two%20Sum%20III%20-%20Data%20structure%20design/README_EN.md) ## 题目描述 +
设计并实现一个 TwoSum 的类,使该类需要支持 add
和 find
的操作。
Design and implement a TwoSum class. It should support the following operations: add
and find
.
add
- Add the number to an internal data structure.
@@ -23,11 +24,8 @@ add(3); add(1); add(2);
find(3) -> true
find(6) -> false
-
-
## Solutions
-
### **Python3**
@@ -43,8 +41,9 @@ find(6) -> false
```
### **...**
+
```
```
-
\ No newline at end of file
+
diff --git a/solution/0100-0199/0171.Excel Sheet Column Number/README.md b/solution/0100-0199/0171.Excel Sheet Column Number/README.md
index 18216072f3f7e..c9b40cdd50e59 100644
--- a/solution/0100-0199/0171.Excel Sheet Column Number/README.md
+++ b/solution/0100-0199/0171.Excel Sheet Column Number/README.md
@@ -1,8 +1,9 @@
-# [171. Excel表列序号](https://leetcode-cn.com/problems/excel-sheet-column-number)
+# [171. Excel 表列序号](https://leetcode-cn.com/problems/excel-sheet-column-number)
[English Version](/solution/0100-0199/0171.Excel%20Sheet%20Column%20Number/README_EN.md)
## 题目描述
+
给定一个Excel表格中的列名称,返回其相应的列序号。
@@ -38,15 +39,14 @@致谢:
特别感谢 @ts 添加此问题并创建所有测试用例。
Given a column title as appear in an Excel sheet, return its corresponding column number.
- +Given a column title as appear in an Excel sheet, return its corresponding column number.
For example:
- -A -> 1 @@ -31,12 +28,8 @@- -
Example 1:
- -Input: "A" @@ -45,12 +38,8 @@- -
Example 2:
- -Input: "AB" @@ -59,12 +48,8 @@- -
Example 3:
- -Input: "ZY" @@ -73,10 +58,8 @@- ## Solutions - ### **Python3** @@ -92,8 +75,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0172.Factorial Trailing Zeroes/README.md b/solution/0100-0199/0172.Factorial Trailing Zeroes/README.md index 1aa9641ca98ff..bca3869a60238 100644 --- a/solution/0100-0199/0172.Factorial Trailing Zeroes/README.md +++ b/solution/0100-0199/0172.Factorial Trailing Zeroes/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0172.Factorial%20Trailing%20Zeroes/README_EN.md) ## 题目描述 +
给定一个整数 n,返回 n! 结果尾数中零的数量。
@@ -20,15 +21,14 @@说明: 你算法的时间复杂度应为 O(log n) 。
- - ## 解法 - + ### **Python3** + ```python @@ -36,6 +36,7 @@ ``` ### **Java** + ```java @@ -43,8 +44,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0172.Factorial Trailing Zeroes/README_EN.md b/solution/0100-0199/0172.Factorial Trailing Zeroes/README_EN.md index 2c580b3ff463c..fd6ec1a2434c5 100644 --- a/solution/0100-0199/0172.Factorial Trailing Zeroes/README_EN.md +++ b/solution/0100-0199/0172.Factorial Trailing Zeroes/README_EN.md @@ -3,14 +3,11 @@ [中文文档](/solution/0100-0199/0172.Factorial%20Trailing%20Zeroes/README.md) ## Description -Given an integer n, return the number of trailing zeroes in n!.
- +Given an integer n, return the number of trailing zeroes in n!.
Example 1:
- -Input: 3 @@ -19,12 +16,8 @@ Explanation: 3! = 6, no trailing zero.- -
Example 2:
- -Input: 5 @@ -33,16 +26,10 @@ Explanation: 5! = 120, one trailing zero.- -
Note: Your solution should be in logarithmic time complexity.
- - - ## Solutions - ### **Python3** @@ -58,8 +45,9 @@ ``` ### **...** + ``` ``` - \ No newline at end of file + diff --git a/solution/0100-0199/0173.Binary Search Tree Iterator/README.md b/solution/0100-0199/0173.Binary Search Tree Iterator/README.md index ba82513247428..f5f98d8de4e4f 100644 --- a/solution/0100-0199/0173.Binary Search Tree Iterator/README.md +++ b/solution/0100-0199/0173.Binary Search Tree Iterator/README.md @@ -3,6 +3,7 @@ [English Version](/solution/0100-0199/0173.Binary%20Search%20Tree%20Iterator/README_EN.md) ## 题目描述 +实现一个二叉搜索树迭代器。你将使用二叉搜索树的根节点初始化迭代器。
@@ -34,15 +35,14 @@ iterator.hasNext(); // 返回 falsenext()
调用总是有效的,也就是说,当调用 next()
时,BST 中至少存在一个下一个最小的数。Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST.
- +Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST.
Calling next()
will return the next smallest number in the BST.
- -
Example:
- -  - -BSTIterator iterator = new BSTIterator(root); @@ -53,27 +42,17 @@ iterator.hasNext(); // return false- -
- -
Note:
- -next()
and hasNext()
should run in average O(1) time and uses O(h) memory, where h is the height of the tree.next()
call will always be valid, that is, there will be at least a next smallest number in the BST when next()
is called.一些恶魔抓住了公主(P)并将她关在了地下城的右下角。地下城是由 M x N 个房间组成的二维网格。我们英勇的骑士(K)最初被安置在左上角的房间里,他必须穿过地下城并通过对抗恶魔来拯救公主。
- -骑士的初始健康点数为一个正整数。如果他的健康点数在某一时刻降至 0 或以下,他会立即死亡。
- -有些房间由恶魔守卫,因此骑士在进入这些房间时会失去健康点数(若房间里的值为负整数,则表示骑士将损失健康点数);其他房间要么是空的(房间里的值为 0),要么包含增加骑士健康点数的魔法球(若房间里的值为正整数,则表示骑士将增加健康点数)。
- -为了尽快到达公主,骑士决定每次只向右或向下移动一步。
- -- -
编写一个函数来计算确保骑士能够拯救到公主所需的最低初始健康点数。
- -例如,考虑到如下布局的地下城,如果骑士遵循最佳路径 右 -> 右 -> 下 -> 下
,则骑士的初始健康点数至少为 7。
-2 (K) | +-2 (K) | --3 | +-3 | -3 | +3 | -
-5 | +-5 | --10 | +-10 | -1 | +1 | -
10 | +10 | -30 | +30 | --5 (P) | +-5 (P) | -
- -
说明:
- -骑士的健康点数没有上限。
+骑士的健康点数没有上限。
-