当前位置:网站首页>315. 计算右侧小于当前元素的个数
315. 计算右侧小于当前元素的个数
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 ,按要求返回一个新数组 counts 。数组 counts 有该性质: counts[i] 的值是 nums[i] 右侧小于 nums[i] 的元素的数量。
示例 1:
输入:nums = [5,2,6,1]
输出:[2,1,1,0]
解释:
5 的右侧有 2 个更小的元素 (2 和 1)
2 的右侧仅有 1 个更小的元素 (1)
6 的右侧有 1 个更小的元素 (1)
1 的右侧有 0 个更小的元素
示例 2:
输入:nums = [-1]
输出:[0]
示例 3:
输入:nums = [-1,-1]
输出:[0,0]
class Solution {
private int[] c;
private int[] a;
public List<Integer> countSmaller(int[] nums) {
List<Integer> resultList = new ArrayList<Integer>();
discretization(nums);
init(nums.length + 5);
for (int i = nums.length - 1; i >= 0; --i) {
int id = getId(nums[i]);
resultList.add(query(id - 1));
update(id);
}
Collections.reverse(resultList);
return resultList;
}
private void init(int length) {
c = new int[length];
Arrays.fill(c, 0);
}
private int lowBit(int x) {
return x & (-x);
}
private void update(int pos) {
while (pos < c.length) {
c[pos] += 1;
pos += lowBit(pos);
}
}
private int query(int pos) {
int ret = 0;
while (pos > 0) {
ret += c[pos];
pos -= lowBit(pos);
}
return ret;
}
private void discretization(int[] nums) {
Set<Integer> set = new HashSet<Integer>();
for (int num : nums) {
set.add(num);
}
int size = set.size();
a = new int[size];
int index = 0;
for (int num : set) {
a[index++] = num;
}
Arrays.sort(a);
}
private int getId(int x) {
return Arrays.binarySearch(a, x) + 1;
}
}
边栏推荐
- core. What is JS ---kalrry
- Summarized benefits
- Chrome删除重复书签
- Sword finger offer 42 Maximum sum of successive subarrays
- 聚焦行业,赋能客户 | 博云容器云产品族五大行业解决方案发布
- Run typescript code directly using TS node
- Media industry under the epidemic situation, small program ecology driven digital transformation exploration
- mysql 函数
- 2121. sum of intervals of the same elements - hash table method
- Badly placed ()‘s 问题
猜你喜欢

The illustration shows three handshakes and four waves. Xiaobai can understand them

【STL】顺序容器之deque用法总结

C语言学习总结

Eureka

Children's programming for comprehensively cultivating students' mental thinking

Sword finger offer 42 Maximum sum of successive subarrays

MySQL basic query

【项目实训】线形箭头的变化

xml dtd 记录

Xxl-sso enables SSO single sign on
随机推荐
Xiaobai must see in investment and wealth management: illustrated fund buying and selling rules
Children's programming for comprehensively cultivating students' mental thinking
Idea automatically generates serialVersionUID
ssm + ftp +ueditor
开源OAuth2框架 实现SSO单点登录
asp.net文件下载demo与相关问题的处理
Add IPAD control function into shairplay
关于五险一金你需要知道的事情
mingw-w64、msys和ffmpeg的配置与编译
ssm + ftp +ueditor
[graduation season · advanced technology Er] it's my choice. I have to walk on my knees
Concepts and differences of DQL, DML, DDL and DCL
Chrome删除重复书签
centos7 mysql 记录
Idea installing the cloudtoolkit plug-in
Xxl-sso enables SSO single sign on
About professional attitude
MySQL redo log redo log
[QT] basic learning notes
Detailed explanation of callback function