84669 personnes étudient
152542 personnes étudient
20005 personnes étudient
5487 personnes étudient
7821 personnes étudient
359900 personnes étudient
3350 personnes étudient
180660 personnes étudient
48569 personnes étudient
18603 personnes étudient
40936 personnes étudient
1549 personnes étudient
1183 personnes étudient
32909 personnes étudient
php实现字符串反转,不用strrev,不借用数组方式,时间复杂度度小于O(n)的,首尾交换的那种实现。
光阴似箭催人老,日月如移越少年。
<?php $str = 'hello world'; $tmp = ''; for($i = strlen($str)-1; $i >= 0; $i--){ $tmp .= $str{$}; } echo $tmp;
貌似不存在O(n/2)这种说法,也还是O(n)
php<?php $str = 'I am Mr.Jing'; // 我去!php中字符串的元素居然是可变的 for ($i=0, $j = strlen($str)-1; $i < $j; $i++, $j--) { $tmp = $str[$j]; $str[$j] = $str[$i]; $str[$i] = $tmp; } // 输出结果 echo $str;
php
<?php $str = 'I am Mr.Jing'; // 我去!php中字符串的元素居然是可变的 for ($i=0, $j = strlen($str)-1; $i < $j; $i++, $j--) { $tmp = $str[$j]; $str[$j] = $str[$i]; $str[$i] = $tmp; } // 输出结果 echo $str;
貌似不存在O(n/2)这种说法,也还是O(n)