LintCode_249 Count of Smaller Number before itself
来源:互联网 发布:淘宝级别的等级划分 编辑:程序博客网 时间:2024/06/10 14:59
Give you an integer array (index from 0 to n-1, where n is the size of this array, 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 before itself I first.
Example
思路是把数依次压入一个vector,不过在压入的时候找到该数的位置,维护这个vector的排序顺序:For array [1,2,7,8,5]
, return [0,1,2,3,2]
class Solution {public: /** * @param A: An integer array * @return: Count the number of element before this element 'ai' is * smaller than it and return count number array */ vector<int> countOfSmallerNumberII(vector<int> &A) { // write your code here vector <int> temp; vector<int> res; for (int i = 0; i < A.size(); i++) { auto itr = lower_bound(temp.begin(), temp.end(), A[i]); int count = itr - temp.begin(); res.push_back(count); temp.insert(itr, A[i]); } return res; }};
0 0
- LintCode_249 Count of Smaller Number before itself
- LintCode_249 Count of Smaller Number before itself
- [LintCode]Count of Smaller Number before itself
- LintCode_284 Count of Smaller Number
- LintCode_248 Count of Smaller Number
- #248 Count of Smaller Number
- [Lintcode]Count of Smaller Number
- lintcode: Count of Smaller Number
- 248.Count of Smaller Number-插入区间(中等题)
- leetcode Count of Smaller Numbers After Self
- leetcode Count of Smaller Numbers After Self
- [LeetCode315]Count of Smaller Numbers After Self
- leetcode Count of Smaller Numbers After Self
- Count of Smaller Numbers After Self | LeetCode
- leetcode Count of Smaller Numbers After Self
- 315Count of Smaller Numbers After Self
- LeetCode Count of Smaller Numbers After Self
- [Leetcode]Count of Smaller Numbers After Self
- 二维数组和字符串之间的互转
- 插件开发之360 DroidPlugin源码分析(四)Activity预注册占坑
- LintCode_212 Space Replacement
- uva 11212 - Editing a Book
- LintCode_248 Count of Smaller Number
- LintCode_249 Count of Smaller Number before itself
- cjsjk
- hive学习练习&Sqoop知识补充
- Java Apache HttpClient post 获取提交参数并获取网页
- hihocoder1077,线段树单点修改的一点小技巧
- Codeforces 598A Tricky Sum【计数】
- CF 678B 暑假集训13(闰年判断)
- Cortex-M KEIL特殊用法
- [FZU 2105 Digits Count] 线段树区间的复合操作