PHP算法之转换成小写字母
2024-09-02 08:27:13
实现函数 ToLowerCase(),该函数接收一个字符串参数 str,并将该字符串中的大写字母转换成小写字母,之后返回新的字符串。
示例 1:
输入: "Hello"
输出: "hello"
示例 2:
输入: "here"
输出: "here"
示例 3:
输入: "LOVELY"
输出: "lovely"
来源:力扣(LeetCode)
代码献上
class Solution {
/**
* @param String $str
* @return String
*/
function toLowerCase($str) {
$strlen = strlen($str);
$arr = str_split($str,1);
$newstr = '';
for($i=0;$i<$strlen;$i++){
$ord = ord($arr[$i]);
if($ord < 97 && $ord > 64){
$newstr.= chr($ord+32);
}else{
$newstr.= $arr[$i];
}
}
return $newstr;
}
}
最新文章
- jpg Test
- How to manage the certificates in the PC
- UISearchBar改变搜索框的高度
- maven install 报错Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project*****
- python堡垒机
- 转载 C#使用Salt + Hash来为密码加密
- static wechat red package tool
- svn“Previous operation has not finished; run &#39;cleanup&#39; if it was interrupted
- Class.getResourceAsStream()与ClassLoader.getResourceAsStream()的区别
- JS 判断是否为IP格式
- 经典面试题:一张表区别DOM解析和SAX解析XML
- 你真的了解webview么?
- 即时通讯(IV)
- git无法识别新增的文件
- Elasticsearch5.5.1插件开发指南
- npm 安装 cannot find module
- HDU 3226 背包
- FreeRTOS 低功耗之待机模式
- mycat引起的insert后马上select不到数据的故障分析
- [分享] 关于App Store下载到一半发生错误的问题 [复制链接]