Lintcode249 Count of Smaller Number before itself solution 题解
【题目描述】
Give you an integer array (index from 0 to n-1, where n is the size of this array, data value from 0 to 10000) . For each element Ai in the array, count the number of element before this element Ai is smaller than it and return count number array.
Notice:We suggest you finish problem Segment Tree Build,Segment Tree Query II and Count of Smaller Number first.
给定一个整数数组(下标由 0 到 n-1, n 表示数组的规模,取值范围由 0 到10000)。对于数组中的每个ai元素,请计算ai前的数中比它小的元素的数量。
【注】:做此题前最好先完成 Segment Tree Build,Segment Tree Query II和Count of Smaller Number
【题目链接】
www.lintcode.com/en/problem/count-of-smaller-number-before-itself/
【题目解析】
此题可用线段树来做。
首先以0-10000为区间建树,并将所有区间count设为0。每一个最小区间(即叶节点)的count代表到目前为止遇到的该数的数量。
然后开始遍历数组,遇到A[i]时,去查0-A[i]-1区间的count,即为比A[i]小的数的数量
查完后将A[i]区间的count加1即可
【参考答案】
www.jiuzhang.com/solutions/count-of-smaller-number-before-itself/
Lintcode249 Count of Smaller Number before itself solution 题解的更多相关文章
- LeetCode "Count of Smaller Number After Self"
Almost identical to LintCode "Count of Smaller Number before Self". Corner case needs to b ...
- Lintcode248 Count of Smaller Number solution 题解
[题目描述] Give you an integer array (index from 0 to n-1, where n is the size of this array, value from ...
- Lintcode: Count of Smaller Number
Give you an integer array (index from 0 to n-1, where n is the size of this array, value from 0 to 1 ...
- LintCode "Count of Smaller Number before itself"
Warning: input could be > 10000... Solution by segment tree: struct Node { Node(), left(nullptr), ...
- Count of Smaller Number before itself
Give you an integer array (index from 0 to n-1, where n is the size of this array, value from 0 to 1 ...
- [Swift]LeetCode315. 计算右侧小于当前元素的个数 | Count of Smaller Numbers After Self
You are given an integer array nums and you have to return a new countsarray. The counts array has t ...
- Count of Smaller Numbers After Self -- LeetCode
You are given an integer array nums and you have to return a new counts array. The counts array has ...
- leetcode 315. Count of Smaller Numbers After Self 两种思路(欢迎探讨更优解法)
说来惭愧,已经四个月没有切 leetcode 上的题目了. 虽然工作中很少(几乎)没有用到什么高级算法,数据结构,但是我一直坚信 "任何语言都会过时,只有数据结构和算法才能永恒". ...
- [LeetCode] 315. Count of Smaller Numbers After Self (Hard)
315. Count of Smaller Numbers After Self class Solution { public: vector<int> countSmaller(vec ...
随机推荐
- No new migrations found. Your system is up-to-date.处理
显然是migrations表中存储的相关操作记录了,删除就好了!!!
- Jenkins系列——使用checkstyle进行代码规范检查【升级版】
1.背景 在<Jenkins系列——使用checkstyle进行代码规范检查>一文中完成了ant实现代码规范检查的例子.但存在以下缺陷: 每个作业都需要配置一个不同的checkstyle ...
- Python 练习册,每天一个小程序----第0000题
题目 第 0000 题: 将你的 QQ 头像(或者微博头像)右上角加上红色的数字,类似于微信未读信息数量那种提示效果. 类似于图中效果 Code: from PIL import Image,Imag ...
- 情景linux--如何解决read命令产生的硬编码问题
情景 我们知道,read命令可以读取文件内容,并把内容赋值给变量. 以如下的数据文件为例. $ cat data.txt 1 201623210021 wangzhiguo 25 2 20162321 ...
- Hibernate5环境搭建
1.导包 Hibernate开发包 数据库的驱动包 2.核心配置文件 核心配置文件(赋值到src下) 1.核心配置文件 对于hibernate的核心配置文件它有两种方式(选其中一种即可 ...
- Hive命令及操作
1.hive表操作 复制表结构 create table denserank_amt like otheravgrank_amt;修改表名 alter table tmp rename to cred ...
- (2018干货系列三)最新PHP学习路线整合
怎么学PHP PHP是一种通用开源脚本语言.语法吸收了C语言.Java和Perl的特点,利于学习,使用广泛,主要适用于Web开发领域. 菜鸟到大神,一步到位,正式开启干货模式: PHP初级开发工程师 ...
- RTLinux编程总结
做过一个有关RTLinux的项目,时间一长,差不多忘光了,现在尽量把原来做过的东西总结一下,以备后用,同时正在做类似项目的一个借鉴平台主机:redhat 8.0目标机:PC104模块.ISA总线脉冲输 ...
- windows 下安装或者卸载memcache
1.安装到系统服务中: 在doc中:执行此软件 memcached.exe -d install(如果提示错误,要找到cmd.exe用管理员身份打开) 2.卸载: 在doc中:执行此软件 memcac ...
- sublime Xdebug 配置
Sublime Text 配置x-debug 配置php 的x-debug 拓展 下载地址 :http://www.xdebug.org/download.php 放到php ext的目录下 然后使用 ...