problemscpp
A collection of my answers to algorithm problems in c++.
Public 成员函数 | Private 成员函数 | 静态 Private 成员函数 | Private 属性 | 所有成员列表
leetcode::count_of_smaller_numbers_after_self::Solution类 参考

#include <leetcode.h>

Public 成员函数

vector< int > countSmaller (vector< int > &nums)
 

Private 成员函数

void Discretization (vector< int > &nums)
 
int getId (int x)
 
void Init (int length)
 
int Query (int pos) const
 
void Update (int pos)
 

静态 Private 成员函数

static int LowBit (int x)
 

Private 属性

vector< int > a
 
vector< int > c
 

详细描述

在文件 leetcode.h3032 行定义.

成员函数说明

◆ countSmaller()

vector< int > leetcode::count_of_smaller_numbers_after_self::Solution::countSmaller ( vector< int > &  nums)

在文件 leetcode.cpp8582 行定义.

8582 {
8583 vector<int> resultList;
8584
8585 Discretization(nums);
8586
8587 Init(nums.size() + 5);
8588
8589 for(int i = static_cast<int>(nums.size()) - 1; i >= 0; --i) {
8590 const int id = getId(nums[i]);
8591 resultList.push_back(Query(id - 1));
8592 Update(id);
8593 }
8594
8595 reverse(resultList.begin(), resultList.end());
8596
8597 return resultList;
8598 }
void reverse(struct ListNode *head)

引用了 Discretization(), getId(), Init(), Query(), acwing::acwing3757::reverse() , 以及 Update().

被这些函数引用 leetcode::count_of_smaller_numbers_after_self::TEST().

◆ Discretization()

void leetcode::count_of_smaller_numbers_after_self::Solution::Discretization ( vector< int > &  nums)
private

在文件 leetcode.cpp8622 行定义.

8622 {
8623 a.assign(nums.begin(), nums.end());
8624 sort(a.begin(), a.end());
8625 a.erase(unique(a.begin(), a.end()), a.end());
8626 }

引用了 a.

被这些函数引用 countSmaller().

◆ getId()

int leetcode::count_of_smaller_numbers_after_self::Solution::getId ( int  x)
private

在文件 leetcode.cpp8628 行定义.

8628{ return lower_bound(a.begin(), a.end(), x) - a.begin() + 1; }

引用了 a.

被这些函数引用 countSmaller().

◆ Init()

void leetcode::count_of_smaller_numbers_after_self::Solution::Init ( int  length)
private

在文件 leetcode.cpp8600 行定义.

8600{ c.resize(length, 0); }

引用了 c.

被这些函数引用 countSmaller().

◆ LowBit()

int leetcode::count_of_smaller_numbers_after_self::Solution::LowBit ( int  x)
staticprivate

在文件 leetcode.cpp8602 行定义.

8602{ return x & -x; }

被这些函数引用 Query() , 以及 Update().

◆ Query()

int leetcode::count_of_smaller_numbers_after_self::Solution::Query ( int  pos) const
private

在文件 leetcode.cpp8611 行定义.

8611 {
8612 int ret = 0;
8613
8614 while(pos > 0) {
8615 ret += c[pos];
8616 pos -= LowBit(pos);
8617 }
8618
8619 return ret;
8620 }

引用了 c , 以及 LowBit().

被这些函数引用 countSmaller().

◆ Update()

void leetcode::count_of_smaller_numbers_after_self::Solution::Update ( int  pos)
private

在文件 leetcode.cpp8604 行定义.

8604 {
8605 while(pos < c.size()) {
8606 c[pos] += 1;
8607 pos += LowBit(pos);
8608 }
8609 }

引用了 c , 以及 LowBit().

被这些函数引用 countSmaller().

类成员变量说明

◆ a

vector<int> leetcode::count_of_smaller_numbers_after_self::Solution::a
private

在文件 leetcode.h3035 行定义.

被这些函数引用 Discretization() , 以及 getId().

◆ c

vector<int> leetcode::count_of_smaller_numbers_after_self::Solution::c
private

在文件 leetcode.h3034 行定义.

被这些函数引用 Init(), Query() , 以及 Update().


该类的文档由以下文件生成: