LintCode_249 Count of Smaller Number before itself
来源:互联网 发布:mac如何切换搜狗输入法 编辑:程序博客网 时间:2024/06/10 14:16
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 IIand Count of Smaller Number before itself I first.
Example
不用线段树, 竟然也过了~~~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
- 51Nod-1417-天堂里的游戏
- Git学习
- LintCode_200 Longest Palindromic Substring
- LintCode_204 Singleton
- LintCode_223 Palindrome Linked List
- LintCode_249 Count of Smaller Number before itself
- LintCode_362 Trapping Rain Water
- LintCode_365 Count 1 in Binary
- make j* make j4 make j8 区别
- find the largest subsquare surrounded by ‘w’ 和‘W’
- 第56课:Spark中的Tungsten内存和CPU的优化使用
- WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!解决办法
- VMware 虚拟机 Ubuntu 系统执行 ifconfig 命令 eth0没有IP地址(intet addr、Bcast、Mask) 解决:UP BROADCAST MULTICAST 问题
- *hdu 2665 (可持久化线段树)