源码之家

  • 首页
  • 文章
  • 问答
  • 下载
您的位置: 首页  >  文章  >  Leetcode 344. Reverse String

Leetcode 344. Reverse String

分类: 文章 • 2022-10-06 16:42:15

文章作者:Tyan
博客:noahsnail.com  |  ****  |  简书

1. Description

Leetcode 344. Reverse String

2. Solution

class Solution {
public:
    string reverseString(string s) {
        int i = 0;
        int j = s.length() - 1;
        while(i < j) {
            swap(s[i++], s[j--]);
        }
        return s;
    }

private:
    void swap(char& a, char& b) {
        char temp = a;
        a = b;
        b = temp;
    }
};

Reference

  1. https://leetcode.com/problems/reverse-string/description/

相关推荐

  • LeetCode206. Reverse Linked
  • LeetCode_NO493_Reverse Pairs 解题报告
  • leetcode刷题-evaluate-reverse-polish-notation
  • leetcode 567【medium】---Permutation in String
  • 【leetcode】150.(Medium)Evaluate Reverse Polish Notation
  • LeetCode-206-Reverse Linked List
  • leetcode 206[easy]-Reverse Linked List
  • Leetcode 206. Reverse Linked List
  • LeetCode606-Construct String from Binary Tree(根据二叉树生成字符串)
  • LeetCode_String #6. ZigZag Conversion (Easy)
  • leetcode 443: String Compression,357: Count Numbers with Unique Digits
  • LeetCode:String to Integer (atoi)
    网站免责声明 网站地图 最新文章 用户隐私 版权申明
本站所有数据收集于网络,如果侵犯到您的权益,请联系网站进行下架处理。   

Copyright © 2018-2021   Powered By 源码之家    备案号:   粤ICP备20058927号