Skip to content

Latest commit

 

History

History
40 lines (31 loc) · 1.02 KB

344.md

File metadata and controls

40 lines (31 loc) · 1.02 KB

✏️Leetcode之PHP版题目解析(344. Reverse String)

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


✏️描述

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


✏️题目实例


     /**
         * @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;
        }

联系