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

#include <leetcode.h>

Public 成员函数

 AllOne ()
 Initializes the object of the data structure. 更多...
 
void dec (const string &key)
 Decrements the count of the string key by 1. If the count of key is 0 after the decrement, remove it from the data structure. It is guaranteed that key exists in the data structure before the decrement. 更多...
 
string getMaxKey ()
 Returns one of the keys with the maximal count. 更多...
 
string getMinKey ()
 Returns one of the keys with the minimum count. 更多...
 
void inc (const string &key)
 Increments the count of the string key by 1. If key does not exist in the data structure, insert it with count 1. 更多...
 

Private 属性

map< int, unordered_set< string > > count_str
 
int max = 0
 
int min = 50000
 
unordered_map< string, int > str_count
 

详细描述

在文件 leetcode.h1748 行定义.

构造及析构函数说明

◆ AllOne()

leetcode::all_oone_data_structure::AllOne::AllOne ( )

Initializes the object of the data structure.

在文件 leetcode.cpp4564 行定义.

4564 {
4565 str_count = unordered_map<string, int>();
4566 count_str = map<int, unordered_set<string>>();
4567 }
map< int, unordered_set< string > > count_str
Definition: leetcode.h:1752
unordered_map< string, int > str_count
Definition: leetcode.h:1751

引用了 count_str , 以及 str_count.

成员函数说明

◆ dec()

void leetcode::all_oone_data_structure::AllOne::dec ( const string &  key)

Decrements the count of the string key by 1. If the count of key is 0 after the decrement, remove it from the data structure. It is guaranteed that key exists in the data structure before the decrement.

在文件 leetcode.cpp4585 行定义.

4585 {
4586 const int prev = str_count[key]--;
4587 if(str_count[key] == 0) {
4588 str_count.erase(key);
4589 }
4590 count_str[prev].erase(key);
4591 if(count_str[prev].empty()) {
4592 count_str.erase(prev);
4593 }
4594 if(prev != 1) {
4595 count_str[prev - 1].insert(key);
4596 }
4597 if(!count_str.empty()) {
4598 min = count_str.begin()->first;
4599 max = count_str.rbegin()->first;
4600 } else {
4601 min = 50000;
4602 max = 0;
4603 }
4604 }

引用了 count_str, max, min , 以及 str_count.

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

◆ getMaxKey()

string leetcode::all_oone_data_structure::AllOne::getMaxKey ( )

Returns one of the keys with the maximal count.

返回
One of the keys with the maximal count. If no element exists, return an empty string "".

在文件 leetcode.cpp4606 行定义.

4606 {
4607 if(str_count.empty()) {
4608 return "";
4609 }
4610 return *count_str[max].begin();
4611 }

引用了 count_str, max , 以及 str_count.

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

◆ getMinKey()

string leetcode::all_oone_data_structure::AllOne::getMinKey ( )

Returns one of the keys with the minimum count.

返回
One of the keys with the minimum count. If no element exists, return an empty string "".

在文件 leetcode.cpp4613 行定义.

4613 {
4614 if(str_count.empty()) {
4615 return "";
4616 }
4617 return *count_str[min].begin();
4618 }

引用了 count_str, min , 以及 str_count.

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

◆ inc()

void leetcode::all_oone_data_structure::AllOne::inc ( const string &  key)

Increments the count of the string key by 1. If key does not exist in the data structure, insert it with count 1.

在文件 leetcode.cpp4569 行定义.

4569 {
4570 const int prev = str_count[key]++;
4571 count_str[prev].erase(key);
4572 count_str[prev + 1].insert(key);
4573 if(count_str[prev].empty()) {
4574 count_str.erase(prev);
4575 }
4576 if(!count_str.empty()) {
4577 min = count_str.begin()->first;
4578 max = count_str.rbegin()->first;
4579 } else {
4580 min = 50000;
4581 max = 0;
4582 }
4583 }

引用了 count_str, max, min , 以及 str_count.

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

类成员变量说明

◆ count_str

map<int, unordered_set<string> > leetcode::all_oone_data_structure::AllOne::count_str
private

在文件 leetcode.h1752 行定义.

被这些函数引用 AllOne(), dec(), getMaxKey(), getMinKey() , 以及 inc().

◆ max

int leetcode::all_oone_data_structure::AllOne::max = 0
private

在文件 leetcode.h1749 行定义.

被这些函数引用 dec(), getMaxKey() , 以及 inc().

◆ min

int leetcode::all_oone_data_structure::AllOne::min = 50000
private

在文件 leetcode.h1750 行定义.

被这些函数引用 dec(), getMinKey() , 以及 inc().

◆ str_count

unordered_map<string, int> leetcode::all_oone_data_structure::AllOne::str_count
private

在文件 leetcode.h1751 行定义.

被这些函数引用 AllOne(), dec(), getMaxKey(), getMinKey() , 以及 inc().


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