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相关推荐

  1. LeetCode 344.Reverse String

    题意: Write a function that takes a string as input and returns the string reversed. Example: Given s ...

  2. LeetCode 344. Reverse String

    题目: Write a function that takes a string as input and returns the string reversed. Example: Given s ...

  3. 【跟Leon一起刷LeetCode】344. Reverse String

    Reverse String Description: Write a function that takes a string as input and returns the string rev ...

  4. LeetCode之Reverse String II

    1.题目 Given a string and an integer k, you need to reverse the first k characters for every 2k charac ...

  5. LeetCode之Reverse String

    1.题目: Write a function that takes a string as input and returns the string reversed. Example: Given ...

  6. String | 344. Reverse String

    题目:反转字符串 方法1: class Solution { public:string reverseString(string s) {int m = (s.size() -1) / 2;for( ...

  7. LeetCode 541. Reverse String II

    题目: Given a string and an integer k, you need to reverse the first k characters for every 2k charact ...

  8. 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 ...

  9. 344.Reverse String

    question: Write a function that takes a string as input and returns the string reversed. Example: Gi ...

最新文章

  1. Notepad++ 列操作
  2. linux ramdisk与tmpfs的深入分析
  3. vue连线 插件_【Vue CLI】手把手教你撸插件
  4. 领域驱动设计,为何死灰复燃?
  5. ERP系统为什么要使用集成的数据和信息平台?
  6. 系统发生 1219 错误。 提供的凭据与已存在的凭据集冲突。
  7. dede php 循环,织梦怎么循环调用多级子栏目如二级栏目下三级栏目
  8. java获取接口数据类型_java中调用第三方接口获取数据的方式
  9. Apache Cassandra和Java入门(第一部分)
  10. Windows下安装scikit-learn
  11. 怎么去掉ECSHOP的Powered by ECShop版权信息
  12. clone方法是如何工作的
  13. 中后台管理信息系统通用原型方案、业务中台管理系统、业务中台架构、管理信息系统、订单管理、客户管理、货源管理、财务管理、客服管理、营销管理、办公申请、协作管理、CMS、OA、CRM、ERP、Axure
  14. linux mysql 建索引_MySQL在创建索引之前一定要想到的事情
  15. linux下shell脚本编程2
  16. python excel模板 生成excel表格_python制作简单excel统计报表3之将mysql数据库中的数据导入excel模板并生成统计图...
  17. linux cgroup学习总结
  18. Linux系统中普通用户输入命令后出现“不在sudoers文件中,此事将被报告”的问题
  19. 《你好啊,程序员》学习笔记
  20. win7系统 (32位)安装包

热门文章

  1. 南阳833--取石子(七)
  2. 启动过程以及故障排除
  3. windows下sqlite3的基本操作
  4. Linux环境中Visual Studio Code的配置使用----编译运行C/C++(良心教程)
  5. 终端html页面,HTML5的终端适配
  6. 如何从阿里云Code升级至Codeup
  7. 数据挖掘与数据仓库区别与联系
  8. 使用tensorflow建模LSTM的详细步骤通俗易懂解读
  9. 感知器调参之梯度下降法
  10. 使用javaHelp制作java swing帮助文档