forked from doocs/leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: generate readme files for lcci questions
生成《程序员面试金典》题目文档
- Loading branch information
Showing
253 changed files
with
10,688 additions
and
953 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# [面试题 01.01. 判定字符是否唯一](https://leetcode-cn.com/problems/is-unique-lcci) | ||
|
||
## 题目描述 | ||
<!-- 这里写题目描述 --> | ||
<p>实现一个算法,确定一个字符串 <code>s</code> 的所有字符是否全都不同。</p> | ||
|
||
<p><strong>示例 1:</strong></p> | ||
|
||
<pre><strong>输入:</strong> <code>s</code> = "leetcode" | ||
<strong>输出:</strong> false | ||
</pre> | ||
|
||
<p><strong>示例 2:</strong></p> | ||
|
||
<pre><strong>输入:</strong> <code>s</code> = "abc" | ||
<strong>输出:</strong> true | ||
</pre> | ||
|
||
<p><strong>限制:</strong></p> | ||
<ul> | ||
<li><code>0 <= len(s) <= 100 </code></li> | ||
<li>如果你不使用额外的数据结构,会很加分。</li> | ||
</ul> | ||
|
||
|
||
## 解法 | ||
<!-- 这里可写通用的实现逻辑 --> | ||
|
||
|
||
### Python3 | ||
<!-- 这里可写当前语言的特殊实现逻辑 --> | ||
|
||
```python | ||
class Solution: | ||
def isUnique(self, astr: str) -> bool: | ||
sets = set(astr) | ||
return len(sets) == len(astr) | ||
``` | ||
|
||
### Java | ||
<!-- 这里可写当前语言的特殊实现逻辑 --> | ||
|
||
```java | ||
class Solution { | ||
public boolean isUnique(String astr) { | ||
char[] chars = astr.toCharArray(); | ||
int len = chars.length; | ||
for (int i = 0; i < len - 1; ++i) { | ||
for (int j = i + 1; j < len; ++j) { | ||
if (chars[i] == chars[j]) { | ||
return false; | ||
} | ||
} | ||
} | ||
return true; | ||
} | ||
} | ||
``` | ||
|
||
### ... | ||
``` | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
# [01.01. Is Unique](https://leetcode-cn.com/problems/is-unique-lcci) | ||
|
||
## Description | ||
<p>Implement an algorithm to determine if a string has all unique characters. What if you cannot use additional data structures?</p> | ||
|
||
|
||
|
||
<p><strong>Example 1:</strong></p> | ||
|
||
|
||
|
||
<pre> | ||
|
||
<strong>Input: </strong><code>s</code> = "leetcode" | ||
|
||
<strong>Output: </strong>false | ||
|
||
</pre> | ||
|
||
|
||
|
||
<p><strong>Example 2:</strong></p> | ||
|
||
|
||
|
||
<pre> | ||
|
||
<strong>Input: </strong><code>s</code> = "abc" | ||
|
||
<strong>Output: </strong>true | ||
|
||
</pre> | ||
|
||
|
||
|
||
<p> </p> | ||
|
||
|
||
|
||
<p><strong>Note:</strong></p> | ||
|
||
|
||
|
||
<ul> | ||
|
||
<li><code>0 <= len(s) <= 100 </code></li> | ||
|
||
</ul> | ||
|
||
|
||
|
||
|
||
## Solutions | ||
|
||
|
||
### Python3 | ||
|
||
```python | ||
class Solution: | ||
def isUnique(self, astr: str) -> bool: | ||
sets = set(astr) | ||
return len(sets) == len(astr) | ||
``` | ||
|
||
### Java | ||
|
||
```java | ||
class Solution { | ||
public boolean isUnique(String astr) { | ||
char[] chars = astr.toCharArray(); | ||
int len = chars.length; | ||
for (int i = 0; i < len - 1; ++i) { | ||
for (int j = i + 1; j < len; ++j) { | ||
if (chars[i] == chars[j]) { | ||
return false; | ||
} | ||
} | ||
} | ||
return true; | ||
} | ||
} | ||
``` | ||
|
||
### ... | ||
``` | ||
``` |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# [面试题 01.02. 判定是否互为字符重排](https://leetcode-cn.com/problems/check-permutation-lcci) | ||
|
||
## 题目描述 | ||
<!-- 这里写题目描述 --> | ||
<p>给定两个字符串 <code>s1</code> 和 <code>s2</code>,请编写一个程序,确定其中一个字符串的字符重新排列后,能否变成另一个字符串。</p> | ||
|
||
<p><strong>示例 1:</strong></p> | ||
|
||
<pre><strong>输入:</strong> <code>s1</code> = "abc", <code>s2</code> = "bca" | ||
<strong>输出:</strong> true | ||
</pre> | ||
|
||
<p><strong>示例 2:</strong></p> | ||
|
||
<pre><strong>输入:</strong> <code>s1</code> = "abc", <code>s2</code> = "bad" | ||
<strong>输出:</strong> false | ||
</pre> | ||
|
||
<p><strong>说明:</strong></p> | ||
|
||
<ul> | ||
<li><code>0 <= len(s1) <= 100 </code></li> | ||
<li><code>0 <= len(s2) <= 100 </code></li> | ||
</ul> | ||
|
||
|
||
## 解法 | ||
<!-- 这里可写通用的实现逻辑 --> | ||
|
||
|
||
### Python3 | ||
<!-- 这里可写当前语言的特殊实现逻辑 --> | ||
|
||
```python | ||
class Solution: | ||
def CheckPermutation(self, s1: str, s2: str) -> bool: | ||
return sorted(s1) == sorted(s2) | ||
``` | ||
|
||
### Java | ||
<!-- 这里可写当前语言的特殊实现逻辑 --> | ||
|
||
```java | ||
|
||
``` | ||
|
||
### ... | ||
``` | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# [01.02. Check Permutation](https://leetcode-cn.com/problems/check-permutation-lcci) | ||
|
||
## Description | ||
<p>Given two strings,write a method to decide if one is a permutation of the other.</p> | ||
|
||
|
||
|
||
<p><strong>Example 1:</strong></p> | ||
|
||
|
||
|
||
<pre> | ||
|
||
<strong>Input: </strong><code>s1</code> = "abc", <code>s2</code> = "bca" | ||
|
||
<strong>Output: </strong>true | ||
|
||
</pre> | ||
|
||
|
||
|
||
<p><strong>Example 2:</strong></p> | ||
|
||
|
||
|
||
<pre> | ||
|
||
<strong>Input: </strong><code>s1</code> = "abc", <code>s2</code> = "bad" | ||
|
||
<strong>Output: </strong>false | ||
|
||
</pre> | ||
|
||
|
||
|
||
<p><strong>Note:</strong></p> | ||
|
||
|
||
|
||
<ol> | ||
|
||
<li><code>0 <= len(s1) <= 100 </code></li> | ||
|
||
<li><code>0 <= len(s2) <= 100</code></li> | ||
|
||
</ol> | ||
|
||
|
||
|
||
|
||
## Solutions | ||
|
||
|
||
### Python3 | ||
|
||
```python | ||
class Solution: | ||
def CheckPermutation(self, s1: str, s2: str) -> bool: | ||
return sorted(s1) == sorted(s2) | ||
``` | ||
|
||
### Java | ||
|
||
```java | ||
|
||
``` | ||
|
||
### ... | ||
``` | ||
``` |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# [面试题 01.03. URL化](https://leetcode-cn.com/problems/string-to-url-lcci) | ||
|
||
## 题目描述 | ||
<!-- 这里写题目描述 --> | ||
<p>URL化。编写一种方法,将字符串中的空格全部替换为<code>%20</code>。假定该字符串尾部有足够的空间存放新增字符,并且知道字符串的“真实”长度。(注:用<code>Java</code>实现的话,请使用字符数组实现,以便直接在数组上操作。)</p> | ||
|
||
<p><strong>示例1:</strong></p> | ||
|
||
<pre><strong> 输入</strong>:"Mr John Smith ", 13 | ||
<strong> 输出</strong>:"Mr%20John%20Smith" | ||
</pre> | ||
|
||
<p><strong>示例2:</strong></p> | ||
|
||
<pre><strong> 输入</strong>:" ", 5 | ||
<strong> 输出</strong>:"%20%20%20%20%20" | ||
</pre> | ||
|
||
<p><strong>提示:</strong></p> | ||
|
||
<ol> | ||
<li>字符串长度在[0, 500000]范围内。</li> | ||
</ol> | ||
|
||
|
||
## 解法 | ||
<!-- 这里可写通用的实现逻辑 --> | ||
|
||
|
||
### Python3 | ||
<!-- 这里可写当前语言的特殊实现逻辑 --> | ||
|
||
```python | ||
class Solution: | ||
def replaceSpaces(self, S: str, length: int) -> str: | ||
S = S[:length] if length < len(S) else S | ||
return S.replace(' ', '%20') | ||
``` | ||
|
||
### Java | ||
<!-- 这里可写当前语言的特殊实现逻辑 --> | ||
|
||
```java | ||
|
||
``` | ||
|
||
### ... | ||
``` | ||
``` |
Oops, something went wrong.