LeetCode 344. Reverse String(反转字符串)
题目描述
- LeetCode 344. 反转字符串
- 请编写一个函数,其功能是将输入的字符串反转过来。
示例
- 输入: s = "hello"
- 返回: "olleh"
Java 解答
class Solution {
public String reverseString(String s) {
if (s == null || s.length() <= 1) {
return s;
}
char[] arr = s.toCharArray();
int length = arr.length;
for (int i = 0; i < length / 2; i++) {
char temp = arr[i];
arr[i] = arr[length - i - 1];
arr[length - i - 1] = temp;
}
return String.valueOf(arr);
//return new StringBuilder(s).reverse().toString();
}
}
LeetCode 344. Reverse String(反转字符串)的更多相关文章
- [LeetCode] 344. Reverse String 翻转字符串
Write a function that reverses a string. The input string is given as an array of characters char[]. ...
- 344 Reverse String 反转字符串
请编写一个函数,其功能是将输入的字符串反转过来.示例:输入:s = "hello"返回:"olleh"详见:https://leetcode.com/probl ...
- Leetcode 344:Reverse String 反转字符串(python、java)
Leetcode 344:Reverse String 反转字符串 公众号:爱写bug Write a function that reverses a string. The input strin ...
- Leetcode#344. Reverse String(反转字符串)
题目描述 编写一个函数,其作用是将输入的字符串反转过来. 示例 1: 输入: "hello" 输出: "olleh" 示例 2: 输入: "A man ...
- [LeetCode] 344 Reverse String && 541 Reverse String II
原题地址: 344 Reverse String: https://leetcode.com/problems/reverse-string/description/ 541 Reverse Stri ...
- 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 字符串处理
题意:反转字符串,用好库函数. class Solution { public: string reverseString(string s) { reverse(s.begin(),s.end()) ...
- (字符串 数组 递归 双指针) 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
Problem: Write a function that takes a string as input and returns the string reversed. Example: Giv ...
随机推荐
- 浏览器报错:unexpected end of input 解决方法
直接上报错代码: <!DOCTYPE html> <html lang="en"> <head> <meta charset=" ...
- UVA 1645 Count
https://vjudge.net/problem/UVA-1645 题意:有多少个n个节点的有根树,每个深度中所有节点的子节点数相同 dp[i] 节点数为i时的答案 除去根节点还有i-1个点,如果 ...
- [洛谷P1822] 魔法指纹
洛谷题目连接:魔法指纹 题目描述 对于任意一个至少两位的正整数n,按如下方式定义magic(n):将n按十进制顺序写下来,依次对相邻两个数写下差的绝对值.这样,得到了一个新数,去掉前导0,则定义为ma ...
- MyBatis框架的使用及源码分析(十三) ResultSetHandler
在PreparedStatementHandler中的query()方法中,用ResultSetHandler来完成结果集的映射. public <E> List<E> que ...
- redis cluster以及master-slave在windows下环境搭建
一.redis cluster环境搭建: 1.了解Redis Cluster原理: 详细了解可参考:http://doc.redisfans.com/topic/cluster-tutorial.ht ...
- iOS 点击cell上的按钮获取行数
-(void)btnClick:(UIButton *)button{ UITableViewCell *cell = (UITableViewCell *)[[button superview] s ...
- SVG 基本绘图方法总结
基本内容: * SVG并不属于HTML5专有内容 * HTML5提供有关SVG原生的内容 * 在HTML5出现之前,就有SVG内容 * SVG,简单来说就是矢量图 * SVG文件 ...
- 32岁白发菜鸟拿2.6万年薪苦熬10年 NBA首秀便惊艳世人 科比书豪纷纷为他点赞
这是一场普通的常规赛——斯台普斯球馆,湖人的赛季第81场.比赛的结果也没什么意外:客场作战的火箭106-99带走胜利.然而,这一场的斯台普斯却成了欢乐的海洋,现场甚至喊出了MVP的呼声,这份赞誉,送给 ...
- 重写strstr、strcpy、memcpy、memset、atof算法
#include<stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> ...
- bootstrap 弹窗 数据清除
bootstrap modal操作简单易用, //清除弹窗原数据 $("#create_modal").on("hidden.bs.modal", functi ...