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 ...
随机推荐
- TensorFlow4Delphi
https://github.com/hartmutdavid/TensorFlow4Delphi
- Ubuntu忘记root密码怎么办?
http://www.linuxidc.com/Linux/2016-05/131256.htm
- MySQL主从复制_复制过滤
关于主从过滤,建议只在从服务器做设定,在Master 端为保证二进制日志的完整, 不建议使用二进制日志过滤. Master 可用参数: binlog-do-db= #定义白名单,仅将制定数据库的相关操 ...
- 初学node.js有感一
Node.js感悟 一.前言 很久以前就对node.js十分的好奇和感兴趣,因为种种原因没能去深入的认识了解和学习掌握这门技术,最近正好要做一些项目,其中就用到了node.js中的一些东西,所以借着使 ...
- 02 浅析Spring的AOP(面向切面编程)
1.关于AOP AOP(Aspect Oriented Programming),即面向切面编程,可以说是OOP(Object Oriented Programming,面向对象编程)的补充和完善.O ...
- POJ - 3126 bfs + 素数筛法 [kuangbin带你飞]专题一
题意:给定两个四位素数作为终点和起点,每次可以改变起点数的某一位,且改变后的数仍然是素数,问是否可能变换成终点数字? 思路:bfs搜索,每次改变四位数中的某一位.素数打表方便判断新生成的数是否是素数. ...
- 情景linux—不曾了解的cat用法
情景 cat是linux命令中最为基础的命令之一,它是"concatenate"(连接)的简写,作用概述是concatenate and print files,即:连接和查看文件 ...
- 基于 HTML5 Canvas 的交互式地铁线路图
前言 前两天在 echarts 上寻找灵感的时候,看到了很多有关地图类似的例子,地图定位等等,但是好像就是没有地铁线路图,就自己花了一些时间捣鼓出来了这个交互式地铁线路图的 Demo,地铁线路上的点是 ...
- 关于使用srping @RequestParam 容易出错的地方
大家都知道,在spring中的@RequestParam主要用户传递参数用的,具体的解释就是将请求参数去数据映射到功能处理方法的参数上.其中包括三个参数: value:参数名字,即入参的请求参数名字, ...
- tcp/ip 卷一 读书笔记(5)arp和rarp 同网段和不同网段之间的通信过程
arp和rarp 同网段和不同网段之间的通信过程 IPv6中已经没有arp rarp协议,所以这里都是IPv4. 链路层使用以太网地址来确定目的地址,应用则常使用ip地址通信 arp协议是指从ip地址 ...