Skip to content

Commit 0f671a5

Browse files
committed
feat: add solutions to lc problems: No.0796,0171
1 parent af64e3d commit 0f671a5

File tree

9 files changed

+146
-28
lines changed

9 files changed

+146
-28
lines changed

Diff for: solution/0100-0199/0171.Excel Sheet Column Number/README.md

+19-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# [171. Excel表列序号](https://leetcode-cn.com/problems/excel-sheet-column-number)
1+
# [171. Excel 表列序号](https://leetcode-cn.com/problems/excel-sheet-column-number)
22

33
[English Version](/solution/0100-0199/0171.Excel%20Sheet%20Column%20Number/README_EN.md)
44

@@ -40,7 +40,6 @@
4040
<p><strong>致谢:</strong><br>
4141
特别感谢&nbsp;<a href="http://leetcode.com/discuss/user/ts">@ts</a>&nbsp;添加此问题并创建所有测试用例。</p>
4242

43-
4443
## 解法
4544

4645
<!-- 这里可写通用的实现逻辑 -->
@@ -80,12 +79,12 @@ class Solution {
8079

8180
```ts
8281
function titleToNumber(columnTitle: string): number {
83-
let res: number = 0;
84-
for (let char of columnTitle) {
85-
res = res * 26 + char.charCodeAt(0) - 64;
86-
}
87-
return res;
88-
};
82+
let res: number = 0;
83+
for (let char of columnTitle) {
84+
res = res * 26 + char.charCodeAt(0) - 64;
85+
}
86+
return res;
87+
}
8988
```
9089

9190
### **C++**
@@ -103,6 +102,18 @@ public:
103102
};
104103
```
105104
105+
### **Go**
106+
107+
```go
108+
func titleToNumber(columnTitle string) int {
109+
res := 0
110+
for _, c := range columnTitle {
111+
res = res*26 + int(c-'A'+1)
112+
}
113+
return res
114+
}
115+
```
116+
106117
### **...**
107118

108119
```

Diff for: solution/0100-0199/0171.Excel Sheet Column Number/README_EN.md

+18-7
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ AB -&gt; 28
5757
<li><code>columnTitle</code> is in the range <code>[&quot;A&quot;, &quot;FXSHRXW&quot;]</code>.</li>
5858
</ul>
5959

60-
6160
## Solutions
6261

6362
<!-- tabs:start -->
@@ -91,12 +90,12 @@ class Solution {
9190

9291
```ts
9392
function titleToNumber(columnTitle: string): number {
94-
let res: number = 0;
95-
for (let char of columnTitle) {
96-
res = res * 26 + char.charCodeAt(0) - 64;
97-
}
98-
return res;
99-
};
93+
let res: number = 0;
94+
for (let char of columnTitle) {
95+
res = res * 26 + char.charCodeAt(0) - 64;
96+
}
97+
return res;
98+
}
10099
```
101100

102101
### **C++**
@@ -114,6 +113,18 @@ public:
114113
};
115114
```
116115
116+
### **Go**
117+
118+
```go
119+
func titleToNumber(columnTitle string) int {
120+
res := 0
121+
for _, c := range columnTitle {
122+
res = res*26 + int(c-'A'+1)
123+
}
124+
return res
125+
}
126+
```
127+
117128
### **...**
118129

119130
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
func titleToNumber(columnTitle string) int {
2+
res := 0
3+
for _, c := range columnTitle {
4+
res = res*26 + int(c-'A'+1)
5+
}
6+
return res
7+
}

Diff for: solution/0700-0799/0796.Rotate String/README.md

+37-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
<li><code>A</code> 和&nbsp;<code>B</code>&nbsp;长度不超过&nbsp;<code>100</code>。</li>
2626
</ul>
2727

28-
2928
## 解法
3029

3130
<!-- 这里可写通用的实现逻辑 -->
@@ -37,15 +36,51 @@
3736
<!-- 这里可写当前语言的特殊实现逻辑 -->
3837

3938
```python
40-
39+
class Solution:
40+
def rotateString(self, s: str, goal: str) -> bool:
41+
if len(s) != len(goal):
42+
return False
43+
return goal in s + s
4144
```
4245

4346
### **Java**
4447

4548
<!-- 这里可写当前语言的特殊实现逻辑 -->
4649

4750
```java
51+
class Solution {
52+
public boolean rotateString(String s, String goal) {
53+
if (s.length() != goal.length()) {
54+
return false;
55+
}
56+
return (s + s).contains(goal);
57+
}
58+
}
59+
```
60+
61+
### **C++**
62+
63+
```cpp
64+
class Solution {
65+
public:
66+
bool rotateString(string s, string goal) {
67+
if (s.size() != goal.size()) {
68+
return false;
69+
}
70+
return !!strstr((s + s).data(), goal.data());
71+
}
72+
};
73+
```
74+
75+
### **Go**
4876
77+
```go
78+
func rotateString(s string, goal string) bool {
79+
if len(s) != len(goal) {
80+
return false
81+
}
82+
return strings.Contains(s+s, goal)
83+
}
4984
```
5085

5186
### **...**

Diff for: solution/0700-0799/0796.Rotate String/README_EN.md

+37-11
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,8 @@
66

77
<p>We are given two strings, <code>A</code> and <code>B</code>.</p>
88

9-
10-
119
<p>A <em>shift on <code>A</code></em> consists of taking string <code>A</code> and moving the leftmost character to the rightmost position. For example, if <code>A = &#39;abcde&#39;</code>, then it will be <code>&#39;bcdea&#39;</code> after one shift on <code>A</code>. Return <code>True</code> if and only if <code>A</code> can become <code>B</code> after some number of shifts on <code>A</code>.</p>
1210

13-
14-
1511
<pre>
1612

1713
<strong>Example 1:</strong>
@@ -30,32 +26,62 @@
3026

3127
</pre>
3228

33-
34-
3529
<p><strong>Note:</strong></p>
3630

37-
38-
3931
<ul>
4032
<li><code>A</code> and <code>B</code> will have length at most <code>100</code>.</li>
4133
</ul>
4234

43-
44-
4535
## Solutions
4636

4737
<!-- tabs:start -->
4838

4939
### **Python3**
5040

5141
```python
52-
42+
class Solution:
43+
def rotateString(self, s: str, goal: str) -> bool:
44+
if len(s) != len(goal):
45+
return False
46+
return goal in s + s
5347
```
5448

5549
### **Java**
5650

5751
```java
52+
class Solution {
53+
public boolean rotateString(String s, String goal) {
54+
if (s.length() != goal.length()) {
55+
return false;
56+
}
57+
return (s + s).contains(goal);
58+
}
59+
}
60+
```
61+
62+
### **C++**
63+
64+
```cpp
65+
class Solution {
66+
public:
67+
bool rotateString(string s, string goal) {
68+
if (s.size() != goal.size()) {
69+
return false;
70+
}
71+
return !!strstr((s + s).data(), goal.data());
72+
}
73+
};
74+
```
75+
76+
### **Go**
5877
78+
```go
79+
func rotateString(s string, goal string) bool {
80+
if len(s) != len(goal) {
81+
return false
82+
}
83+
return strings.Contains(s+s, goal)
84+
}
5985
```
6086

6187
### **...**

Diff for: solution/0700-0799/0796.Rotate String/Solution.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class Solution {
2+
public:
3+
bool rotateString(string s, string goal) {
4+
if (s.size() != goal.size()) {
5+
return false;
6+
}
7+
return !!strstr((s + s).data(), goal.data());
8+
}
9+
};

Diff for: solution/0700-0799/0796.Rotate String/Solution.go

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
func rotateString(s string, goal string) bool {
2+
if len(s) != len(goal) {
3+
return false
4+
}
5+
return strings.Contains(s+s, goal)
6+
}

Diff for: solution/0700-0799/0796.Rotate String/Solution.java

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class Solution {
2+
public boolean rotateString(String s, String goal) {
3+
if (s.length() != goal.length()) {
4+
return false;
5+
}
6+
return (s + s).contains(goal);
7+
}
8+
}

Diff for: solution/0700-0799/0796.Rotate String/Solution.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class Solution:
2+
def rotateString(self, s: str, goal: str) -> bool:
3+
if len(s) != len(goal):
4+
return False
5+
return goal in s + s

0 commit comments

Comments
 (0)