344.md

April 27, 2019 · View on GitHub

:pencil2:Leetcode之PHP版题目解析(344. Reverse String)

2019-04-24 吴亲库里 库里的深夜食堂


:pencil2:描述

写一个函数反转数组中的字符串,要求是只能原地换,也就是说只能使用O(1)的空间复杂度.


:pencil2:题目实例

​
     /**
         * @param String[] $s
         * @return NULL
         */
        function reverseString(&$s) {
            $j=count($s)-1;
            for($i=0;$i<$j;$i++){
                $temp=$s[$i];
                $s[$i]=$s[$j];
                $s[$j]=$temp;
                $j--;
            }; 
            return $s;
        }

联系

​

Contents

  1. 1:pencil2:Leetcode之PHP版题目解析(344. Reverse String)
  2. 1.1:pencil2:描述
  3. 1.2:pencil2:题目实例