当前位置:网站首页>315. calculate the number of elements on the right that are smaller than the current element
315. calculate the number of elements on the right that are smaller than the current element
2022-06-23 07:08:00 【Graduation_ Design】
Preface
C++ It's a high-level programming language , from C Language expansion and upgrading , As early as 1979 By Benjani · Strauss LUP is AT&T Developed by Bell studio .
C++ Both can be carried out C Process programming of language , It can also be used for object-based programming characterized by abstract data types , It can also carry out object-oriented programming characterized by inheritance and polymorphism .C++ Good at object-oriented programming at the same time , You can also do process based programming .
C++ Have the practical characteristics of computer operation , At the same time, it is also committed to improving the programming quality of large-scale programs and the problem description ability of programming languages .
Java Is an object-oriented programming language , Not only absorbed C++ The advantages of language , It's abandoned C++ The incomprehensible inheritance in 、 Concepts such as pointer , therefore Java Language has two characteristics: powerful and easy to use .Java As the representative of static object-oriented programming language , Excellent implementation of object-oriented theory , Allow programmers to do complex programming in an elegant way of thinking .
Java It's simple 、 object-oriented 、 Distributed 、 Robustness, 、 Security 、 Platform independence and portability 、 Multithreading 、 Dynamic and so on .Java Can write desktop applications 、Web Applications 、 Distributed system and embedded system applications, etc .
Python By Guido of the Dutch Society for mathematical and computer science research · Van rosum On 1990 It was designed in the early 's , As a course called ABC A substitute for language .Python Provides efficient advanced data structure , It's also a simple and effective way of object-oriented programming .Python Syntax and dynamic types , And the nature of interpretative language , Make it a programming language for scripting and rapid application development on most platforms , With the continuous update of the version and the addition of new language features , Gradually used for independent 、 Development of large projects .
Python The interpreter is easy to extend , have access to C Language or C++( Or something else can be done through C Calling language ) Expand new functions and data types .Python It can also be used as an extensible programming language in customizable software .Python Rich library of standards , Provides source code or machine code for each major system platform .
2021 year 10 month , Compiler for language popularity index Tiobe take Python Crowned the most popular programming language ,20 Put it in... For the first time in years Java、C and JavaScript above .
describe
Give you an array of integers nums , Returns a new array as required counts . Array counts It has this property : counts[i] The value of is nums[i] Right side less than nums[i] The number of elements .
Example 1:
Input :nums = [5,2,6,1]
Output :[2,1,1,0]
explain :
5 On the right side of the wall is 2 A smaller element (2 and 1)
2 On the right side of the road is just 1 A smaller element (1)
6 On the right side of the wall is 1 A smaller element (1)
1 On the right side of the wall is 0 A smaller element
Example 2:
Input :nums = [-1]
Output :[0]
Example 3:
Input :nums = [-1,-1]
Output :[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;
}
}
边栏推荐
猜你喜欢

【STL】关联容器之unordered_map用法总结

宝塔忘记密码
![[STL] summary of map usage of associated containers](/img/1d/1b6488ea47face0548500b1e1ec60d.png)
[STL] summary of map usage of associated containers

Solve the mining virus sshd2 (redis does not set a password and clear the crontab scheduled task)

994. rotten oranges - non recursive method

20220621 Dual Quaternion
![[bull Chinese document] queue package used to process distributed jobs and messages in nodejs](/img/f9/1bd79d3754c1b4d1b114d02283f95e.png)
[bull Chinese document] queue package used to process distributed jobs and messages in nodejs

深度学习系列47:styleGAN总结

Badly placed()'s problem

【项目实训】线形箭头的变化
随机推荐
Badly placed()'s problem
TP6+Redis+think-queue+Supervisor实现进程常驻消息队列/job任务
关于五险一金你需要知道的事情
【STL】关联容器之map用法总结
【Qt】基础学习笔记
406-双指针(27. 移除元素、977.有序数组的平方、15. 三数之和、18. 四数之和)
901. 股票价格跨度
cmder
Summarized benefits
300. 最长递增子序列
ssm + ftp +ueditor
RFID数据安全性实验:C#可视化实现奇偶校验、CRC冗余校验、海明码校验
20220621 Dual Quaternion
Project_ Filter to solve Chinese garbled code
回调函数详解
899. 有序队列
MySQL MVCC多版本并发控制
MySQL optimization
小白投资理财必看:图解基金买入与卖出规则
897. 递增顺序搜索树