1.使对象可以像数组一样进行foreach循环,要求属性必须是私有.(Iterator模式的PHP5实现,写一类实现Iterator接口) <?php class Test implements Iterator{ private $item = array('id'=>1,'name'=>'php'); public function rewind(){ reset($this->item); } public function current(){ return current
一.求以下表达式的值,写出您想到的一种或几种实现方法: 1-2+3-4+……+m //方法一,通过顺序规律写程序,同时也知道flag标志位的重要性. static int F1(int m) { int sum =0; bool flag =true; for (int i = 1; i <= m; i++) { if (flag) //一次是默认是True,下下也为True sum += i; else sum -= i; flag = !flag; } return sum; } //通过奇
标题 Maximum Depth of Binary Tree 描述 The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node. c++实现方法代码 1.递归实现,时间复杂度为O(n) 空间复杂度为O(logn) /** * Definition for binary tree * struct TreeNode { * int