标签:ons weight ola java ram bsp comment splay san
实现函数 ToLowerCase(),该函数接收一个字符串参数 str,并将该字符串中的大写字母转换成小写字母,之后返回新的字符串。
示例 1:
输入: "Hello"
输出: "hello"
示例 2:
输入: "here"
输出: "here"
示例 3:
输入: "LOVELY"
输出: "lovely"
1var lower = ‘abcdefghijklmnopqrstuvwxyz‘
2var upper = ‘ABCDEFGHIJKLMNOPQRSTUVWXYZ‘
3
4var find = function (s, target) {
5 var l = s.length
6 if (s.includes(target)) {
7 for (var i=0; i<l; i++) {
8 if (s[i] === target) return i
9 }
10 }
11 return -1
12}
13
14var toLowerCase = function (str) {
15 var r = ‘‘
16
17 for (var i = 0; i < str.length; i++) {
18 // 是大写 就转化成小写
19 if (upper.includes(str[i])) {
20 var idx = find(upper, str[i])
21 r += lower[idx]
22 } else {
23 // 是小写就直接拼接上去
24 r += str[i]
25 }
26 }
27 return r
28}
标签:ons weight ola java ram bsp comment splay san
原文地址:https://www.cnblogs.com/rencoo/p/9783646.html