zoukankan      html  css  js  c++  java
  • 344. Reverse String

    Write a function that takes a string as input and returns the string reversed.

    Example:
    Given s = "hello", return "olleh".

    反转字符串,逼我不用 reverse

    class Solution {
    public:
        string reverseString(string s) {
            int n = s.length();
            int l = 0, r = n - 1;
            while(l < r) {
                swap(s[l++],s[r--]);
            }
            return s;
        }
    };
  • 相关阅读:
    NYOJ 734
    NYOJ 762
    NYOJ 743
    NYOJ 478
    NYOJ 451
    NYOJ 461
    NYOJ 485
    NYOJ 333
    平均互信息
    ASCII码
  • 原文地址:https://www.cnblogs.com/pk28/p/7247632.html
Copyright © 2011-2022 走看看