当前位置:网站首页>303. 区域和检索 - 数组不可变
303. 区域和检索 - 数组不可变
2022-06-23 06:14:00 【毕业_设计】
前言
C++是一种计算机高级程序设计语言,由C语言扩展升级而产生 ,最早于1979年由本贾尼·斯特劳斯特卢普在AT&T贝尔工作室研发。
C++既可以进行C语言的过程化程序设计,又可以进行以抽象数据类型为特点的基于对象的程序设计,还可以进行以继承和多态为特点的面向对象的程序设计。C++擅长面向对象程序设计的同时,还可以进行基于过程的程序设计。
C++拥有计算机运行的实用性特征,同时还致力于提高大规模程序的编程质量与程序设计语言的问题描述能力。
Java是一门面向对象的编程语言,不仅吸收了C++语言的各种优点,还摒弃了C++里难以理解的多继承、指针等概念,因此Java语言具有功能强大和简单易用两个特征。Java语言作为静态面向对象编程语言的代表,极好地实现了面向对象理论,允许程序员以优雅的思维方式进行复杂的编程 。
Java具有简单性、面向对象、分布式、健壮性、安全性、平台独立与可移植性、多线程、动态性等特点 。Java可以编写桌面应用程序、Web应用程序、分布式系统和嵌入式系统应用程序等 。
Python由荷兰数学和计算机科学研究学会的吉多·范罗苏姆 于1990 年代初设计,作为一门叫做ABC语言的替代品。Python提供了高效的高级数据结构,还能简单有效地面向对象编程。Python语法和动态类型,以及解释型语言的本质,使它成为多数平台上写脚本和快速开发应用的编程语言,随着版本的不断更新和语言新功能的添加,逐渐被用于独立的、大型项目的开发。
Python解释器易于扩展,可以使用C语言或C++(或者其他可以通过C调用的语言)扩展新的功能和数据类型。Python 也可用于可定制化软件中的扩展程序语言。Python丰富的标准库,提供了适用于各个主要系统平台的源码或机器码。
2021年10月,语言流行指数的编译器Tiobe将Python加冕为最受欢迎的编程语言,20年来首次将其置于Java、C和JavaScript之上。
描述
给定一个整数数组 nums,处理以下类型的多个查询:
计算索引 left 和 right (包含 left 和 right)之间的 nums 元素的 和 ,其中 left <= right
实现 NumArray 类:
NumArray(int[] nums) 使用数组 nums 初始化对象
int sumRange(int i, int j) 返回数组 nums 中索引 left 和 right 之间的元素的 总和 ,包含 left 和 right 两点(也就是 nums[left] + nums[left + 1] + ... + nums[right] )
示例 1:
输入:
["NumArray", "sumRange", "sumRange", "sumRange"]
[[[-2, 0, 3, -5, 2, -1]], [0, 2], [2, 5], [0, 5]]
输出:
[null, 1, -1, -3]
解释:
NumArray numArray = new NumArray([-2, 0, 3, -5, 2, -1]);
numArray.sumRange(0, 2); // return 1 ((-2) + 0 + 3)
numArray.sumRange(2, 5); // return -1 (3 + (-5) + 2 + (-1))
numArray.sumRange(0, 5); // return -3 ((-2) + 0 + 3 + (-5) + 2 + (-1))
class NumArray {
int[] sums;
public NumArray(int[] nums) {
int n = nums.length;
sums = new int[n + 1];
for (int i = 0; i < n; i++) {
sums[i + 1] = sums[i] + nums[i];
}
}
public int sumRange(int i, int j) {
return sums[j + 1] - sums[i];
}
}
边栏推荐
猜你喜欢
![[STL] summary of deque usage of sequential containers](/img/33/65c54d14697ee43b2655ea1255d67d.png)
[STL] summary of deque usage of sequential containers

Easy EDA learning notes 09 esp32-wroom-32e module esp32-devkitc-v4 development board one click download circuit

Why does TCP protocol shake hands three times instead of two?

如何迁移virtualbox 的虚拟机到hype-v

【STL】pair用法总结

EndNote20使用教程分享(未完

Common setup modes (Abstract Factory & responsibility chain mode & observer mode)

redux Actions may not have an undefined “type“ property. Have you misspelled a constant?

Run typescript code directly using TS node
![[daily training] 513 Find the value in the lower left corner of the tree](/img/97/ab2179d6dbd0536e8cc139659aecc2.png)
[daily training] 513 Find the value in the lower left corner of the tree
随机推荐
Idea installing the cloudtoolkit plug-in
[STL] summary of stack and queue usage of container adapter
【STL】pair用法总结
【日常训练】513. 找树左下角的值
EndNote20使用教程分享(未完
mysql 基础查询
Verilog语法讲解
mysql 优化
Intentional shared lock, intentional exclusive lock and deadlock of MySQL
idea安装 CloudToolkit 插件
C语言学习总结
【Qt】基础学习笔记
MySQL的意向共享锁、意向排它锁和死锁
The illustration shows three handshakes and four waves. Xiaobai can understand them
Drawing and resetting of mars3d point, line and surface
[bull Chinese document] queue package used to process distributed jobs and messages in nodejs
Cetos7 record
xml dtd 记录
Using fuser to view file usage
【畢業季·進擊的技術er】自己的選擇,跪著也要走