forked from doocs/leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSolution.go
41 lines (36 loc) · 966 Bytes
/
Solution.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
type Bank struct {
balance []int64
n int
}
func Constructor(balance []int64) Bank {
return Bank{balance, len(balance)}
}
func (this *Bank) Transfer(account1 int, account2 int, money int64) bool {
if account1 > this.n || account2 > this.n || this.balance[account1-1] < money {
return false
}
this.balance[account1-1] -= money
this.balance[account2-1] += money
return true
}
func (this *Bank) Deposit(account int, money int64) bool {
if account > this.n {
return false
}
this.balance[account-1] += money
return true
}
func (this *Bank) Withdraw(account int, money int64) bool {
if account > this.n || this.balance[account-1] < money {
return false
}
this.balance[account-1] -= money
return true
}
/**
* Your Bank object will be instantiated and called as such:
* obj := Constructor(balance);
* param_1 := obj.Transfer(account1,account2,money);
* param_2 := obj.Deposit(account,money);
* param_3 := obj.Withdraw(account,money);
*/