-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path0709.go
49 lines (43 loc) · 1.02 KB
/
0709.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Source: https://leetcode.com/problems/to-lower-case
// Title: To Lower Case
// Difficulty: Easy
// Author: Mu Yang <http://muyang.pro>
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// 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.
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
package main
import (
"strings"
)
func toLowerCase(s string) string {
sb := strings.Builder{}
for _, c := range s {
if 'A' <= c && c <= 'Z' {
sb.WriteRune(c - 'A' + 'a')
} else {
sb.WriteRune(c)
}
}
return sb.String()
}