LeetCode: 344. Reverse String
051102
题目
Write a function that reverses a string. The input string is given as an array of characters char[].
Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory.
You may assume all the characters consist of printable ascii characters.
Example 1:
Input: ["h","e","l","l","o"]
Output: ["o","l","l","e","h"]
Example 2:
Input: ["H","a","n","n","a","h"]
Output: ["h","a","n","n","a","H"]
我的解题思路
这道题是要求char字符的逆,这时候把头和尾对应的元素交换就好了。
class Solution {
public:void reverseString(vector<char>& s) {int head=0, tail=s.size()-1;while(head<tail){swap(s[head],s[tail]);head+=1;tail-=1;}}
};
LeetCode: 344. Reverse String相关推荐
- LeetCode 344.Reverse String
题意: Write a function that takes a string as input and returns the string reversed. Example: Given s ...
- LeetCode 344. Reverse String
题目: Write a function that takes a string as input and returns the string reversed. Example: Given s ...
- 【跟Leon一起刷LeetCode】344. Reverse String
Reverse String Description: Write a function that takes a string as input and returns the string rev ...
- LeetCode之Reverse String II
1.题目 Given a string and an integer k, you need to reverse the first k characters for every 2k charac ...
- LeetCode之Reverse String
1.题目: Write a function that takes a string as input and returns the string reversed. Example: Given ...
- String | 344. Reverse String
题目:反转字符串 方法1: class Solution { public:string reverseString(string s) {int m = (s.size() -1) / 2;for( ...
- LeetCode 541. Reverse String II
题目: Given a string and an integer k, you need to reverse the first k characters for every 2k charact ...
- Leet Code OJ 344. Reverse String [Difficulty: Easy]
题目: Write a function that takes a string as input and returns the string reversed. Example: Given s ...
- 344.Reverse String
question: Write a function that takes a string as input and returns the string reversed. Example: Gi ...
最新文章
- Notepad++ 列操作
- linux ramdisk与tmpfs的深入分析
- vue连线 插件_【Vue CLI】手把手教你撸插件
- 领域驱动设计,为何死灰复燃?
- ERP系统为什么要使用集成的数据和信息平台?
- 系统发生 1219 错误。 提供的凭据与已存在的凭据集冲突。
- dede php 循环,织梦怎么循环调用多级子栏目如二级栏目下三级栏目
- java获取接口数据类型_java中调用第三方接口获取数据的方式
- Apache Cassandra和Java入门(第一部分)
- Windows下安装scikit-learn
- 怎么去掉ECSHOP的Powered by ECShop版权信息
- clone方法是如何工作的
- 中后台管理信息系统通用原型方案、业务中台管理系统、业务中台架构、管理信息系统、订单管理、客户管理、货源管理、财务管理、客服管理、营销管理、办公申请、协作管理、CMS、OA、CRM、ERP、Axure
- linux mysql 建索引_MySQL在创建索引之前一定要想到的事情
- linux下shell脚本编程2
- python excel模板 生成excel表格_python制作简单excel统计报表3之将mysql数据库中的数据导入excel模板并生成统计图...
- linux cgroup学习总结
- Linux系统中普通用户输入命令后出现“不在sudoers文件中,此事将被报告”的问题
- 《你好啊,程序员》学习笔记
- win7系统 (32位)安装包