Skip to content

Commit 11746b7

Browse files
authored
Create ToLowerCase.swift
1 parent 401fabe commit 11746b7

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

Algorithm/leetcode/ToLowerCase.swift

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// https://leetcode.com/problems/to-lower-case
2+
3+
import Foundation
4+
5+
func toLowerCase(_ str: String) -> String {
6+
var result = ""
7+
8+
// 주어진 문자열의 ascii code 값을 구한다
9+
for index in str.utf16 {
10+
if index >= 65 && index <= 90 {
11+
// ascii code로 대문자일 경우 소문자 ascii code로 변경한다 (+ 32)
12+
// 결과 문자열에 더한다
13+
result += String(UnicodeScalar(index + 32)!)
14+
}else{
15+
result += String(UnicodeScalar(index)!)
16+
}
17+
}
18+
19+
// 결과 리턴
20+
return result
21+
}
22+
23+
toLowerCase("al&phaBET")
24+

0 commit comments

Comments
 (0)