Skip to content

Latest commit

 

History

History
55 lines (43 loc) · 1.39 KB

303.md

File metadata and controls

55 lines (43 loc) · 1.39 KB

✏️Leetcode之PHP版题目解析(303. Range Sum Query - Immutable)

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


✏️描述

给定一个整型数组,指定的区间让你求区间之间和的值,我这里实现的时间复杂度是O(n),空间复杂度也是O(n),这里可以优化的是空间复杂度


✏️题目实例

****
   class NumArray {
       /**
        * @param Integer[] $nums
        */
       private $nums;
   
       function __construct($nums) {
           $this->nums=$nums;
       }
     
       /**
        * @param Integer $i
        * @param Integer $j
        * @return Integer
        */
       function sumRange($i, $j) {
           
           while($i<=$j){
               $res +=$this->nums[$i];
               $i++;
           }
           return $res;
       }
   }
   
   /**
    * Your NumArray object will be instantiated and called as such:
    * $obj = NumArray($nums);
    * $ret_1 = $obj->sumRange($i, $j);
    */

联系