PHP-leetcode-307

littlehero發表於2019-09-09
class NumArray
{

    private $nums;

    /**
     * @param Integer[] $nums
     */
    function __construct($nums)
    {
        $this->nums = $nums;
    }

    /**
     * @param Integer $i
     * @param Integer $val
     * @return NULL
     */
    function update($i, $val)
    {
        $this->nums[$i] = $val;
    }

    /**
     * @param Integer $i
     * @param Integer $j
     * @return Integer
     */
    function sumRange($i, $j)
    {
        $index = $i;
        $sum = 0;
        for ($index; $index <= $j; $index++) {
            $sum += $this->nums[$index];
        }
        return $sum;
    }
}