Skip to content

Commit ce3f14f

Browse files
committed
feat: add leetcode solutions: No.0709. To Lower Case
1 parent 62be0dd commit ce3f14f

File tree

5 files changed

+75
-5
lines changed

5 files changed

+75
-5
lines changed

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
dark: {
4848
background: 'rgb(28,32,34)',
4949
highlightColor: '#e96900',
50-
codeBackgroudColor: 'rgb(34,39,46)',
50+
codeBackgroundColor: 'rgb(34,39,46)',
5151
codeTextColor: '#b4b4b4',
5252
},
5353
light: {

solution/0700-0799/0709.To Lower Case/README.md

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,46 @@
3232

3333
<!-- 这里可写通用的实现逻辑 -->
3434

35+
遍历字符串,遇到大写的字符,转小写。
36+
3537
<!-- tabs:start -->
3638

3739
### **Python3**
3840

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

4143
```python
42-
44+
class Solution:
45+
def toLowerCase(self, str: str) -> str:
46+
if not str:
47+
return str
48+
n = len(str)
49+
res = []
50+
for i in range(n):
51+
c = ord(str[i])
52+
if c >= 65 and c <= 90:
53+
c += 32
54+
res.append(chr(c))
55+
return ''.join(res)
4356
```
4457

4558
### **Java**
4659

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

4962
```java
50-
63+
class Solution {
64+
public String toLowerCase(String str) {
65+
int n;
66+
if (str == null || (n = str.length()) == 0) return str;
67+
char[] chars = str.toCharArray();
68+
for (int i = 0; i < chars.length; ++i) {
69+
boolean isUpper = chars[i] >= 'A' && chars[i] <= 'Z';
70+
if (isUpper) chars[i] += 32;
71+
}
72+
return new String(chars);
73+
}
74+
}
5175
```
5276

5377
### **...**

solution/0700-0799/0709.To Lower Case/README_EN.md

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,35 @@
5757
### **Python3**
5858

5959
```python
60-
60+
class Solution:
61+
def toLowerCase(self, str: str) -> str:
62+
if not str:
63+
return str
64+
n = len(str)
65+
res = []
66+
for i in range(n):
67+
c = ord(str[i])
68+
if c >= 65 and c <= 90:
69+
c += 32
70+
res.append(chr(c))
71+
return ''.join(res)
6172
```
6273

6374
### **Java**
6475

6576
```java
66-
77+
class Solution {
78+
public String toLowerCase(String str) {
79+
int n;
80+
if (str == null || (n = str.length()) == 0) return str;
81+
char[] chars = str.toCharArray();
82+
for (int i = 0; i < chars.length; ++i) {
83+
boolean isUpper = chars[i] >= 'A' && chars[i] <= 'Z';
84+
if (isUpper) chars[i] += 32;
85+
}
86+
return new String(chars);
87+
}
88+
}
6789
```
6890

6991
### **...**
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution {
2+
public String toLowerCase(String str) {
3+
int n;
4+
if (str == null || (n = str.length()) == 0) return str;
5+
char[] chars = str.toCharArray();
6+
for (int i = 0; i < chars.length; ++i) {
7+
boolean isUpper = chars[i] >= 'A' && chars[i] <= 'Z';
8+
if (isUpper) chars[i] += 32;
9+
}
10+
return new String(chars);
11+
}
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution:
2+
def toLowerCase(self, str: str) -> str:
3+
if not str:
4+
return str
5+
n = len(str)
6+
res = []
7+
for i in range(n):
8+
c = ord(str[i])
9+
if c >= 65 and c <= 90:
10+
c += 32
11+
res.append(chr(c))
12+
return ''.join(res)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy