mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-07-06 09:23:19 +08:00
Add solution 709
This commit is contained in:
12
leetcode/0709.To-Lower-Case/709. To Lower Case.go
Normal file
12
leetcode/0709.To-Lower-Case/709. To Lower Case.go
Normal file
@ -0,0 +1,12 @@
|
||||
package leetcode
|
||||
|
||||
func toLowerCase(s string) string {
|
||||
runes := []rune(s)
|
||||
diff := 'a' - 'A'
|
||||
for i := 0; i < len(s); i++ {
|
||||
if runes[i] >= 'A' && runes[i] <= 'Z' {
|
||||
runes[i] += diff
|
||||
}
|
||||
}
|
||||
return string(runes)
|
||||
}
|
52
leetcode/0709.To-Lower-Case/709. To Lower Case_test.go
Normal file
52
leetcode/0709.To-Lower-Case/709. To Lower Case_test.go
Normal file
@ -0,0 +1,52 @@
|
||||
package leetcode
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
type question709 struct {
|
||||
para709
|
||||
ans709
|
||||
}
|
||||
|
||||
// para 是参数
|
||||
// one 代表第一个参数
|
||||
type para709 struct {
|
||||
one string
|
||||
}
|
||||
|
||||
// ans 是答案
|
||||
// one 代表第一个答案
|
||||
type ans709 struct {
|
||||
one string
|
||||
}
|
||||
|
||||
func Test_Problem709(t *testing.T) {
|
||||
|
||||
qs := []question709{
|
||||
|
||||
{
|
||||
para709{"Hello"},
|
||||
ans709{"hello"},
|
||||
},
|
||||
|
||||
{
|
||||
para709{"here"},
|
||||
ans709{"here"},
|
||||
},
|
||||
|
||||
{
|
||||
para709{"LOVELY"},
|
||||
ans709{"lovely"},
|
||||
},
|
||||
}
|
||||
|
||||
fmt.Printf("------------------------Leetcode Problem 709------------------------\n")
|
||||
|
||||
for _, q := range qs {
|
||||
_, p := q.ans709, q.para709
|
||||
fmt.Printf("【input】:%v 【output】:%v\n", p, toLowerCase(p.one))
|
||||
}
|
||||
fmt.Printf("\n\n\n")
|
||||
}
|
55
leetcode/0709.To-Lower-Case/README.md
Normal file
55
leetcode/0709.To-Lower-Case/README.md
Normal file
@ -0,0 +1,55 @@
|
||||
# [709. To Lower Case](https://leetcode.com/problems/to-lower-case/)
|
||||
|
||||
|
||||
## 题目
|
||||
|
||||
Given a string `s`, return *the string after replacing every uppercase letter with the same lowercase letter*.
|
||||
|
||||
**Example 1:**
|
||||
|
||||
```
|
||||
Input: s = "Hello"
|
||||
Output: "hello"
|
||||
```
|
||||
|
||||
**Example 2:**
|
||||
|
||||
```
|
||||
Input: s = "here"
|
||||
Output: "here"
|
||||
```
|
||||
|
||||
**Example 3:**
|
||||
|
||||
```
|
||||
Input: s = "LOVELY"
|
||||
Output: "lovely"
|
||||
```
|
||||
|
||||
**Constraints:**
|
||||
|
||||
- `1 <= s.length <= 100`
|
||||
- `s` consists of printable ASCII characters.
|
||||
|
||||
## 题目大意
|
||||
|
||||
给你一个字符串 s ,将该字符串中的大写字母转换成相同的小写字母,返回新的字符串。
|
||||
|
||||
## 解题思路
|
||||
|
||||
- 简单题,将字符串中的大写字母转换成小写字母。
|
||||
|
||||
## 代码
|
||||
|
||||
```go
|
||||
func toLowerCase(s string) string {
|
||||
runes := [] rune(s)
|
||||
diff := 'a' - 'A'
|
||||
for i := 0; i < len(s); i++ {
|
||||
if runes[i] >= 'A' && runes[i] <= 'Z' {
|
||||
runes[i] += diff
|
||||
}
|
||||
}
|
||||
return string(runes)
|
||||
}
|
||||
```
|
Reference in New Issue
Block a user