To Lower Case

Description

Implement function ToLowerCase() that has a string parameter str, and returns the same string in lowercase.

Example 1:

Input: "Hello"
Output: "hello"

Example 2:

Input: "here"
Output: "here"

Example 3:

Input: "LOVELY"
Output: "lovely"

Discuss

直接遍历就可以

Code

class Solution {
public String toLowerCase(String str) {
if (str == null || str.length() == 0) { return null; }
StringBuilder sb = new StringBuilder();
for (int i = 0; i < str.length(); i++) {
char c = str.charAt(i);
if (c >= 'A' && c <= 'Z') {
c += 32;
sb.append(Character.toString((char)c));
continue;
}
sb.append(c);
}
return sb.toString();
}
}

【Leetcode】709. To Lower Case的更多相关文章

  1. 【LeetCode】709. To Lower Case 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述: 题目大意 解题方法 ASIIC码操作 日期 题目地址:https:// ...

  2. 【Leetcode_easy】709. To Lower Case

    problem 709. To Lower Case solution1: class Solution { public: string toLowerCase(string str) { stri ...

  3. 【LeetCode】375. Guess Number Higher or Lower II 解题报告(Python)

    [LeetCode]375. Guess Number Higher or Lower II 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://f ...

  4. Leetcode#709. To Lower Case(转换成小写字母)

    题目描述 实现函数 ToLowerCase(),该函数接收一个字符串参数 str,并将该字符串中的大写字母转换成小写字母,之后返回新的字符串. 示例 1: 输入: "Hello" ...

  5. 709. To Lower Case - LeetCode

    Question 709. To Lower Case Sollution 题目大意:字符串大写转小写 思路: 直接调用Java API函数 字符串转char数组,遍历数组,判断如果大写就转小写 Ja ...

  6. 【LeetCode】392. Is Subsequence 解题报告(Python)

    [LeetCode]392. Is Subsequence 解题报告(Python) 标签: LeetCode 题目地址:https://leetcode.com/problems/is-subseq ...

  7. 【leetcode】657. Robot Return to Origin

    Algorithm [leetcode]657. Robot Return to Origin https://leetcode.com/problems/robot-return-to-origin ...

  8. 【LeetCode】代码模板,刷题必会

    目录 二分查找 排序的写法 BFS的写法 DFS的写法 回溯法 树 递归 迭代 前序遍历 中序遍历 后序遍历 构建完全二叉树 并查集 前缀树 图遍历 Dijkstra算法 Floyd-Warshall ...

  9. 【LeetCode】Gas Station 解题报告

    [LeetCode]Gas Station 解题报告 标签(空格分隔): LeetCode 题目地址:https://leetcode.com/problems/gas-station/#/descr ...

随机推荐

  1. ubuntu 可以加速播放的播放器SMPlayer 16.4安装

    直接贴命令 sudo apt-add-repository ppa:rvm/smplayer sudo apt-get update sudo apt-get install smplayer smp ...

  2. OC extern和变量

    注意: extern只能用来声明全部变量,不能拿来定义变量 #include <stdio.h> // 第一种做法是将a定义在main函数的前面 // int a; // 完整地声明全部变 ...

  3. 【luogu P1462 通往奥格瑞玛的道路】 题解

    题目链接:https://www.luogu.org/problemnew/show/P1462 记住HP=0也叫死. #include <queue> #include <cstd ...

  4. Python程序的执行原理(转)

    1. 过程概述 Python先把代码(.py文件)编译成字节码,交给字节码虚拟机,然后虚拟机一条一条执行字节码指令,从而完成程序的执行. 2. 字节码 字节码在Python虚拟机程序里对应的是PyCo ...

  5. sql中 decode() 的用法

    sql中 decode() 的用法 SELECT ID,DECODE(inParam,'Param','value1' ,'value2') name FROM yytj2018 如果 inParam ...

  6. SpringBoot非官方教程 | 第十九篇: 验证表单信息

    转载请标明出处: 原文首发于:https://www.fangzhipeng.com/springboot/2017/07/11/springboot19/ 本文出自方志朋的博客 这篇文篇主要简述如何 ...

  7. Django-rest-framework(七)swagger使用

    在我们接口开发完之后,需要交付给别人对接,在没有使用swagger的时候,我们需要单独编写一份api接口文档,由postman之类的工具进行请求得到返回的结果.而有了swagger之后,可以通过提取接 ...

  8. requirements.txt 快速备份与安装项目所需安装包

    在查看项目时,通常会有一个requirements.txt 文件, requirements.txt 文件是用于记录所有依赖包及其精确的版本号,便于项目在其它电脑时新环境部署构建项目所需要的运行环境. ...

  9. xcode7--iOS开发---将app打包发布至app store

    时隔3个月再次接触应用打包,又是一顿折腾 说说这次的感受吧: 变得是打包时间减少到4小时(其中大部分时间还是xcode7或者是iOS9的原因),不变的是还是一如既往的坑!! 好了,废话不多说,下面讲讲 ...

  10. wsgiref手写一个web服务端

    ''' 通过wsgiref写一个web服务端先讲讲wsgiref吧,基于网络通信其根本就是基于socket,所以wsgiref同样也是通过对socket进行封装,避免写过多的代码,将一系列的操作封装成 ...