LeetCode题目-303

首页 编程分享 LEET_CODE 正文

leetCode 转载 编程分享 2021-10-26 06:38:18

简介 LeetCode题目-303


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


✏描述

给定一个整型数组,指定的区间让你求区间之间和的值,我这里实现的时间复杂度是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);
    */

转载链接:https://leetcode.cn/


Tags:


本篇评论 —— 揽流光,涤眉霜,清露烈酒一口话苍茫。


    声明:参照站内规则,不文明言论将会删除,谢谢合作。


      最新评论




ABOUT ME

Blogger:袅袅牧童 | Arkin

Ido:PHP攻城狮

WeChat:nnmutong

Email:nnmutong@icloud.com

标签云