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

#include <leetcode.h>

Public 成员函数

 Bank (vector< long long > &balance)
 Initializes the object with the 0-indexed integer array balance. 更多...
 
bool deposit (int account, long long money)
 Deposit money dollars into the account numbered account. 更多...
 
bool transfer (int account1, int account2, long long money)
 Transfers money dollars from the account numbered account1 to the account numbered account2. 更多...
 
bool withdraw (int account, long long money)
 Withdraw money dollars from the account numbered account. 更多...
 

Private 属性

unordered_map< int, long long > accounts
 

详细描述

在文件 leetcode.h1781 行定义.

构造及析构函数说明

◆ Bank()

leetcode::simple_bank_system::Bank::Bank ( vector< long long > &  balance)
explicit

Initializes the object with the 0-indexed integer array balance.

在文件 leetcode.cpp4645 行定义.

4645 {
4646 accounts = unordered_map<int, long long>(balance.size());
4647 for(int i = 0; i < balance.size(); i++) {
4648 accounts[i + 1] = balance[i];
4649 }
4650 }
unordered_map< int, long long > accounts
Definition: leetcode.h:1782

引用了 accounts.

成员函数说明

◆ deposit()

bool leetcode::simple_bank_system::Bank::deposit ( int  account,
long long  money 
)

Deposit money dollars into the account numbered account.

返回
True if the transaction was successful, false otherwise.

在文件 leetcode.cpp4664 行定义.

4664 {
4665 if(!accounts.contains(account)) {
4666 return false;
4667 }
4668 accounts[account] += money;
4669 return true;
4670 }

引用了 accounts.

◆ transfer()

bool leetcode::simple_bank_system::Bank::transfer ( int  account1,
int  account2,
long long  money 
)

Transfers money dollars from the account numbered account1 to the account numbered account2.

返回
True if the transaction was successful, false otherwise.

在文件 leetcode.cpp4652 行定义.

4652 {
4653 if(!accounts.contains(account1) || !accounts.contains(account2)) {
4654 return false;
4655 }
4656 if(accounts[account1] < money) {
4657 return false;
4658 }
4659 accounts[account1] -= money;
4660 accounts[account2] += money;
4661 return true;
4662 }

引用了 accounts.

◆ withdraw()

bool leetcode::simple_bank_system::Bank::withdraw ( int  account,
long long  money 
)

Withdraw money dollars from the account numbered account.

返回
True if the transaction was successful, false otherwise.

在文件 leetcode.cpp4672 行定义.

4672 {
4673 if(!accounts.contains(account)) {
4674 return false;
4675 }
4676 if(accounts[account] < money) {
4677 return false;
4678 }
4679 accounts[account] -= money;
4680 return true;
4681 }

引用了 accounts.

类成员变量说明

◆ accounts

unordered_map<int, long long> leetcode::simple_bank_system::Bank::accounts
private

在文件 leetcode.h1782 行定义.

被这些函数引用 Bank(), deposit(), transfer() , 以及 withdraw().


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