Give you an integer array (index from 0 to n-1, where n is the size of this array, value from 0 to 10000) and an query list. For each query, give you an integer, return the number of element in the array that are smaller than the given integer. Have…
Warning: input could be > 10000... Solution by segment tree: struct Node { Node(), left(nullptr), right(nullptr) {}; int start; int end; int cnt; // Node *left; Node *right; }; class Solution { Node *pRoot; void update(int v) { Node *p = pRoot; while…
Almost identical to LintCode "Count of Smaller Number before Self". Corner case needs to be taken care of. class Solution { ////////////////// // Fenwick Tree // vector<long long> ft; void update(int i, long long x) { ) { ft[] ++; return;…
[题目描述] 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 ar…
[题目描述] Give you an integer array (index from 0 to n-1, where n is the size of this array, value from 0 to 10000) and an query list. For each query, give you an integer, return the number of element in the array that are smaller than the given integer…
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 elementAi is smaller than it and return count number array. Example…
You are given an integer array nums and you have to return a new countsarray. The counts array has the property where counts[i] is the number of smaller elements to the right of nums[i]. Example: Input: [5,2,6,1] Output: [2,1,1,0] Explanation: To the…
说来惭愧,已经四个月没有切 leetcode 上的题目了. 虽然工作中很少(几乎)没有用到什么高级算法,数据结构,但是我一直坚信 "任何语言都会过时,只有数据结构和算法才能永恒".leetcode 上的题目,截止目前切了 137 道(all solutions),只写过 6 篇题解,所以我会写题解的一般都是自认为还蛮有意思或者蛮典型的题目,就比如这道题. 题目链接:Count of Smaller Numbers After Self 这道题很有意思,给出一个数组,返回一个新的数组,新…
315. Count of Smaller Numbers After Self class Solution { public: vector<int> countSmaller(vector<int>& nums) { int n = nums.size(); vector<int> v(n); for (int i = n - 1; i >= 0; --i) { int val = nums[i]; int L = i + 1, R = n - 1;…
说来惭愧,已经四个月没有切 leetcode 上的题目了. 虽然工作中很少(几乎)没有用到什么高级算法,数据结构,但是我一直坚信 "任何语言都会过时,只有数据结构和算法才能永恒".leetcode 上的题目,截止目前切了 137 道(all solutions),只写过 6 篇题解,所以我会写题解的一般都是自认为还蛮有意思或者蛮典型的题目,就比如这道题. 题目链接:Count of Smaller Numbers After Self 这道题很有意思,给出一个数组,返回一个新的数组,新…