替换空格
<?php
class Solution {/*** @param String $s* @return String*/function replaceSpace($s) {$arr=str_split($s); //转化成数组foreach($arr as &$item){if($item==' '){//执行替换操作$item='%20';}}return implode('',$arr); //数组转化成字符串返回}
}
反转链表
<?php
/*** Definition for a singly-linked list.* class ListNode {* public $val = 0;* public $next = null;* function __construct($val = 0, $next = null) {* $this->val = $val;* $this->next = $next;* }* }*/
class Solution {/*** @param ListNode $head* @return ListNode*/function reverseList($head) {$cur = $head;$pre = NULL;while($cur){$temp = $cur->next; $cur->next = $pre;$pre = $cur;$cur = $temp;}return $pre;}
}