Skip to content

Commit 4b71a9d

Browse files
committed
feat: add solutions for lcci problems
添加两道面试题
1 parent e90a6d9 commit 4b71a9d

File tree

7 files changed

+162
-0
lines changed

7 files changed

+162
-0
lines changed

lcci/template.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
> 请按照如下模版创建每一题的 README.md 文档,谢谢!
2+
3+
# [题目](这里是题目链接,如:https://leetcode-cn.com/problems/is-unique-lcci/)
4+
5+
## 题目描述
6+
...
7+
8+
9+
## 解法
10+
### Python3
11+
```python
12+
13+
```
14+
15+
### Java
16+
```java
17+
18+
```
19+
20+
### ...
21+
```
22+
23+
```
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# [面试题 01.01. 判定字符是否唯一](https://leetcode-cn.com/problems/is-unique-lcci/)
2+
3+
## 题目描述
4+
实现一个算法,确定一个字符串 `s` 的所有字符是否全都不同。
5+
6+
**示例 1:**
7+
```
8+
输入: s = "leetcode"
9+
输出: false
10+
```
11+
12+
**示例 2:**
13+
```
14+
输入: s = "abc"
15+
输出: true
16+
```
17+
18+
限制:
19+
20+
- `0 <= len(s) <= 100`
21+
- 如果你不使用额外的数据结构,会很加分。
22+
23+
24+
## 解法
25+
### Python3
26+
```python
27+
class Solution:
28+
def isUnique(self, astr: str) -> bool:
29+
sets = set(astr)
30+
return len(sets) == len(astr)
31+
```
32+
33+
### Java
34+
```java
35+
class Solution {
36+
public boolean isUnique(String astr) {
37+
char[] chars = astr.toCharArray();
38+
int len = chars.length;
39+
for (int i = 0; i < len - 1; ++i) {
40+
for (int j = i + 1; j < len; ++j) {
41+
if (chars[i] == chars[j]) {
42+
return false;
43+
}
44+
}
45+
}
46+
return true;
47+
}
48+
}
49+
```
50+
51+
### ...
52+
```
53+
54+
```
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution {
2+
public boolean isUnique(String astr) {
3+
char[] chars = astr.toCharArray();
4+
int len = chars.length;
5+
for (int i = 0; i < len - 1; ++i) {
6+
for (int j = i + 1; j < len; ++j) {
7+
if (chars[i] == chars[j]) {
8+
return false;
9+
}
10+
}
11+
}
12+
return true;
13+
}
14+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class Solution:
2+
def isUnique(self, astr: str) -> bool:
3+
sets = set(astr)
4+
return len(sets) == len(astr)
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# [面试题 01.02. 判定是否互为字符重排](https://leetcode-cn.com/problems/check-permutation-lcci/)
2+
3+
## 题目描述
4+
给定两个字符串 `s1``s2`,请编写一个程序,确定其中一个字符串的字符重新排列后,能否变成另一个字符串。
5+
6+
**示例 1:**
7+
8+
```
9+
输入: s1 = "abc", s2 = "bca"
10+
输出: true
11+
```
12+
13+
**示例 2:**
14+
```
15+
输入: s1 = "abc", s2 = "bad"
16+
输出: false
17+
```
18+
19+
**说明:**
20+
21+
- `0 <= len(s1) <= 100`
22+
- `0 <= len(s2) <= 100`
23+
24+
25+
## 解法
26+
### Python3
27+
```python
28+
class Solution:
29+
def CheckPermutation(self, s1: str, s2: str) -> bool:
30+
return sorted(s1) == sorted(s2)
31+
```
32+
33+
### Java
34+
```java
35+
36+
```
37+
38+
### ...
39+
```
40+
41+
```
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class Solution:
2+
def CheckPermutation(self, s1: str, s2: str) -> bool:
3+
return sorted(s1) == sorted(s2)

lcof/template.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
> 请按照如下模版创建每一题的 README.md 文档,谢谢!
2+
3+
# [题目](这里是题目链接,如:https://leetcode-cn.com/problems/shu-zu-zhong-zhong-fu-de-shu-zi-lcof/)
4+
5+
## 题目描述
6+
...
7+
8+
9+
## 解法
10+
### Python3
11+
```python
12+
13+
```
14+
15+
### Java
16+
```java
17+
18+
```
19+
20+
### ...
21+
```
22+
23+
```

0 commit comments

Comments
 (0)