LeetCode(69)-Reverse String
题目:
Write a function that takes a string as input and returns the string reversed.
Example:
Given s = "hello", return "olleh".
思路:
- 题意:反转字符串
- 不用考虑为空的情况,这种情况sb.toString()也是null,倒叙遍历,StringBuffer相加
代码:
public class Solution {
public String reverseString(String s) {
StringBuffer sb = new StringBuffer();
int n = s.length();
for(int i = n-1;i >= 0;i--){
sb.append(s.charAt(i));
}
return sb.toString();
}
}
LeetCode(69)-Reverse String的更多相关文章
- [LeetCode] 344 Reverse String && 541 Reverse String II
原题地址: 344 Reverse String: https://leetcode.com/problems/reverse-string/description/ 541 Reverse Stri ...
- LeetCode 541. Reverse String II (反转字符串 II)
Given a string and an integer k, you need to reverse the first k characters for every 2k characters ...
- [LeetCode] 344. Reverse String 翻转字符串
Write a function that reverses a string. The input string is given as an array of characters char[]. ...
- Leetcode#344. Reverse String(反转字符串)
题目描述 编写一个函数,其作用是将输入的字符串反转过来. 示例 1: 输入: "hello" 输出: "olleh" 示例 2: 输入: "A man ...
- leetcode 344. Reverse String 、541. Reverse String II 、796. Rotate String
344. Reverse String 最基础的旋转字符串 class Solution { public: void reverseString(vector<char>& s) ...
- LeetCode 344. Reverse String(反转字符串)
题目描述 LeetCode 344. 反转字符串 请编写一个函数,其功能是将输入的字符串反转过来. 示例 输入: s = "hello" 返回: "olleh" ...
- Leetcode 344 Reverse String 字符串处理
题意:反转字符串,用好库函数. class Solution { public: string reverseString(string s) { reverse(s.begin(),s.end()) ...
- LeetCode 344. Reverse String
Problem: Write a function that takes a string as input and returns the string reversed. Example: Giv ...
- Python [Leetcode 344]Reverse String
题目描述: Write a function that takes a string as input and returns the string reversed. Example:Given s ...
随机推荐
- Android 读取清单文件<meta-data>元素的数据
添加属性 <application -- > <meta-data android:value="Channel_0" android:name="UM ...
- cassandra 如何写数据以及放置副本
application发送数据到server application 发送请求到server 根据设置的load balance 规则从cluster中挑选一个coordinator,一般使用轮询即可 ...
- SYBASE的select into与insert into使用和区别
对于表的部分或全部字段的复制,Sybase数据库提供了两种方式:select into和insert into. select into: 语法:select value1, value2, val ...
- 自定义圆角透明的Dialog
自定义圆角透明的Dialog 说明 系统默认的Dialog默认是背景不透明的,有时候项目需要Dialog为圆角透明,这个时候的解决方案就是---重写Dialog - 系统样式 - 自定义以后的样式 自 ...
- Java基础----Java---集合框架---泛型、泛型方法、静态方法泛型、泛型接口、泛型限定、泛型类
泛型:jdk1.5后的新特性,用于解决安全问题,是一个安全机制. 好处: 1.将运行时的异常出现问题classcastException.转移到了编译时期.方便程序员调试解决问题,让运行事情问题减少, ...
- 06 Activity显示跳转
<span style="font-size:18px;">package com.fmy.day8_29task; import com.fmy.day8_29tas ...
- UNIX网络编程——客户/服务器程序设计示范(四)
TCP预先派生子进程服务器程序,accept使用线程上锁保护 我们使用线程上锁保护accept,因为这种方法不仅适用于同一进程内各线程之间的上锁,而且适用于不同进程之间的上锁. ...
- J2EE Exception:WELD-001408 Unsatisfied dependencies for type [SelectModelFactory] with qualifiers [@
Issue: When you inject some resources using @Inject, you may encounter following exception after app ...
- 在ROS(indigo)中读取手机GPS用于机器人定位~GPS2BT在ubuntu和window系统下的使用方法~
在ROS(indigo)中读取手机GPS用于机器人定位~GPS2BT在ubuntu和window系统下的使用方法~ 不需要额外购买GPS设备. 将手机GPS数据通过蓝牙传输给计算机使用,当然通过类似方 ...
- Chipmunk碰撞回调短时间内重入的解决办法
Chipmunk引擎中碰撞行为可能在细微处与一般认识略有不同. 比如碰撞回调方法可能会重入.不知道方法(函数)重入概念的童鞋可以自行谷哥或度娘. 第一次碰撞方法还未返回,第二次碰撞回调又被调用了.至于 ...