Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f6c08dd

Browse files
Merge pull request SharingSource#27 from SharingSource/ac_oier
✨feat: Add 168 & Modify 815
2 parents b6394ae + 8aa3c60 commit f6c08dd

File tree

3 files changed

+84
-7
lines changed

3 files changed

+84
-7
lines changed

‎Index/模拟.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
| [59. 螺旋矩阵 II](https://leetcode-cn.com/problems/spiral-matrix-ii/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/spiral-matrix-ii/solution/yi-ti-shuang-jie-xiang-jie-xing-zhuang-j-24x8/) | 中等 | 🤩🤩🤩🤩 |
1616
| [65. 有效数字](https://leetcode-cn.com/problems/valid-number/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/valid-number/solution/gong-shui-san-xie-zi-fu-chuan-mo-ni-by-a-7cgc/) | 困难 | 🤩🤩🤩 |
1717
| [73. 矩阵置零](https://leetcode-cn.com/problems/set-matrix-zeroes/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/valid-number/solution/gong-shui-san-xie-zi-fu-chuan-mo-ni-by-a-7cgc/) | 中等 | 🤩🤩🤩🤩 |
18+
| [168. Excel表列名称](https://leetcode-cn.com/problems/excel-sheet-column-title/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/excel-sheet-column-title/solution/gong-shui-san-xie-cong-1-kai-shi-de-26-j-g2ur/) | 简单 | 🤩🤩🤩 |
1819
| [190. 颠倒二进制位](https://leetcode-cn.com/problems/reverse-bits/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/reverse-bits/solution/yi-ti-san-jie-dui-cheng-wei-zhu-wei-fen-ub1hi/) | 简单 | 🤩🤩🤩 |
1920
| [263. 丑数](https://leetcode-cn.com/problems/ugly-number/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/ugly-number/solution/gong-shui-san-xie-jian-dan-de-fen-qing-k-dlvg/) | 简单 | 🤩🤩 |
2021
| [566. 重塑矩阵](https://leetcode-cn.com/problems/reshape-the-matrix/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/reshape-the-matrix/solution/jian-dan-ti-zhong-quan-chu-ji-ke-yi-kan-79gv5/) | 简单 | 🤩🤩🤩 |
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
### 题目描述
2+
3+
这是 LeetCode 上的 **[168. Excel表列名称](https://leetcode-cn.com/problems/excel-sheet-column-title/solution/gong-shui-san-xie-cong-1-kai-shi-de-26-j-g2ur/)** ,难度为 **简单**
4+
5+
Tag : 「模拟」
6+
7+
给定一个正整数,返回它在 Excel 表中相对应的列名称。
8+
9+
例如,
10+
```
11+
1 -> A
12+
2 -> B
13+
3 -> C
14+
...
15+
26 -> Z
16+
27 -> AA
17+
28 -> AB
18+
...
19+
```
20+
示例 1:
21+
```
22+
输入: 1
23+
输出: "A"
24+
```
25+
示例 2:
26+
```
27+
输入: 28
28+
输出: "AB"
29+
```
30+
示例 3:
31+
```
32+
输入: 701
33+
输出: "ZY"
34+
```
35+
36+
---
37+
38+
### 模拟
39+
40+
这是一道从 1ドル$ 开始的的 26ドル$ 进制转换题。
41+
42+
对于一般性的进制转换题目,只需要不断地对 $columnNumber$ 进行 `%` 运算取得最后一位,然后对 $columnNumber$ 进行 `/` 运算,将已经取得的位数去掉,直到 $columnNumber$ 为 0ドル$ 即可。
43+
44+
一般性的进制转换题目无须进行额外操作,是因为我们是在「每一位数值范围在 $[0,x)$」的前提下进行「逢 $x$ 进一」。
45+
46+
但本题需要我们将从 1ドル$ 开始,因此在执行「进制转换」操作前,我们需要先对 $columnNumber$ 执行减一操作,从而实现整体偏移。
47+
48+
代码:
49+
```Java []
50+
class Solution {
51+
public String convertToTitle(int cn) {
52+
StringBuilder sb = new StringBuilder();
53+
while (cn > 0) {
54+
cn--;
55+
sb.append((char)(cn % 26 + 'A'));
56+
cn /= 26;
57+
}
58+
sb.reverse();
59+
return sb.toString();
60+
}
61+
}
62+
```
63+
* 时间复杂度:$O(\log_{26}{cn})$
64+
* 空间复杂度:不算构造答案所消耗的空间,复杂度为 $O(1)$
65+
66+
---
67+
68+
### 最后
69+
70+
这是我们「刷穿 LeetCode」系列文章的第 `No.168` 篇,系列开始于 2021年01月01日,截止于起始日 LeetCode 上共有 1916 道题目,部分是有锁题,我们将先将所有不带锁的题目刷完。
71+
72+
在这个系列文章里面,除了讲解解题思路以外,还会尽可能给出最为简洁的代码。如果涉及通解还会相应的代码模板。
73+
74+
为了方便各位同学能够电脑上进行调试和提交代码,我建立了相关的仓库:https://github.com/SharingSource/LogicStack-LeetCode
75+
76+
在仓库地址里,你可以看到系列文章的题解链接、系列文章的相应代码、LeetCode 原题链接和其他优选题解。
77+

‎LeetCode/811-820/815. 公交路线(困难).md‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Tag : 「图论 BFS」、「双向 BFS」、「图论搜索」
4242

4343
### 基本分析
4444

45-
为了方便,我们令每辆公交站为一个「车站」,由一个「车站」可以进入一条或多条「路线」。
45+
为了方便,我们令每个公交站为一个「车站」,由一个「车站」可以进入一条或多条「路线」。
4646

4747
问题为从「起点车站」到「终点车站」,所进入的最少路线为多少。
4848

@@ -200,25 +200,24 @@ class Solution {
200200

201201
// 双向 BFS
202202
while (!d1.isEmpty() && !d2.isEmpty()) {
203-
int t = -1;
203+
int res = -1;
204204
if (d1.size() <= d2.size()) {
205-
t = update(d1, m1, m2, t);
205+
res = update(d1, m1, m2);
206206
} else {
207-
t = update(d2, m2, m1, s);
207+
res = update(d2, m2, m1);
208208
}
209-
if (t != -1) return t;
209+
if (res != -1) return res;
210210
}
211211

212212
return 0x3f3f3f3f; // never
213213
}
214-
int update(Deque<Integer> d, Map<Integer, Integer> cur, Map<Integer, Integer> other, inttarget) {
214+
int update(Deque<Integer> d, Map<Integer, Integer> cur, Map<Integer, Integer> other) {
215215
// 取出当前所在的路线,与进入该路线所花费的距离
216216
int poll = d.pollFirst();
217217
int step = cur.get(poll);
218218

219219
// 遍历该路线所包含的车站
220220
for (int station : rs[poll]) {
221-
if (station == target) return step;
222221
// 遍历将由该线路的车站发起的路线
223222
Set<Integer> lines = map.get(station);
224223
if (lines == null) continue;

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /