< Summary

Information
Class: LeetCode.Algorithms.SimpleBankSystem.SimpleBankSystemLookup
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\SimpleBankSystem\SimpleBankSystemLookup.cs
Line coverage
83%
Covered lines: 31
Uncovered lines: 6
Coverable lines: 37
Total lines: 106
Line coverage: 83.7%
Branch coverage
66%
Covered branches: 8
Total branches: 12
Branch coverage: 66.6%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
Transfer(...)66.66%6684.61%
Deposit(...)50%2275%
Withdraw(...)75%4481.81%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\SimpleBankSystem\SimpleBankSystemLookup.cs

#LineLine coverage
 1// --------------------------------------------------------------------------------
 2// Copyright (C) 2026 Eugene Eremeev (also known as Yevhenii Yeriemeieiv).
 3// All Rights Reserved.
 4// --------------------------------------------------------------------------------
 5// This software is the confidential and proprietary information of Eugene Eremeev
 6// (also known as Yevhenii Yeriemeieiv) ("Confidential Information"). You shall not
 7// disclose such Confidential Information and shall use it only in accordance with
 8// the terms of the license agreement you entered into with Eugene Eremeev (also
 9// known as Yevhenii Yeriemeieiv).
 10// --------------------------------------------------------------------------------
 11
 12namespace LeetCode.Algorithms.SimpleBankSystem;
 13
 14/// <inheritdoc />
 15public sealed class SimpleBankSystemLookup : ISimpleBankSystem
 16{
 17    private readonly long[] _balance;
 18    private readonly int _balanceLength;
 19
 20    /// <summary>
 21    ///     Time complexity - O(1)
 22    ///     Space complexity - O(n)
 23    /// </summary>
 24    /// <param name="balance"></param>
 125    public SimpleBankSystemLookup(long[] balance)
 126    {
 127        _balance = balance;
 128        _balanceLength = balance.Length;
 129    }
 30
 31    /// <summary>
 32    ///     Time complexity - O(1)
 33    ///     Space complexity - O(1)
 34    /// </summary>
 35    /// <param name="account1"></param>
 36    /// <param name="account2"></param>
 37    /// <param name="money"></param>
 38    /// <returns></returns>
 39    public bool Transfer(int account1, int account2, long money)
 240    {
 241        if (account1 > _balanceLength || account2 > _balanceLength)
 042        {
 043            return false;
 44        }
 45
 246        var balance1Index = account1 - 1;
 247        var balance2Index = account2 - 1;
 48
 249        if (_balance[balance1Index] < money)
 150        {
 151            return false;
 52        }
 53
 154        _balance[balance1Index] -= money;
 155        _balance[balance2Index] += money;
 56
 157        return true;
 258    }
 59
 60    /// <summary>
 61    ///     Time complexity - O(1)
 62    ///     Space complexity - O(1)
 63    /// </summary>
 64    /// <param name="account"></param>
 65    /// <param name="money"></param>
 66    /// <returns></returns>
 67    public bool Deposit(int account, long money)
 168    {
 169        if (account > _balanceLength)
 070        {
 071            return false;
 72        }
 73
 174        var balanceIndex = account - 1;
 75
 176        _balance[balanceIndex] += money;
 77
 178        return true;
 179    }
 80
 81    /// <summary>
 82    ///     Time complexity - O(1)
 83    ///     Space complexity - O(1)
 84    /// </summary>
 85    /// <param name="account"></param>
 86    /// <param name="money"></param>
 87    /// <returns></returns>
 88    public bool Withdraw(int account, long money)
 289    {
 290        if (account > _balanceLength)
 191        {
 192            return false;
 93        }
 94
 195        var balanceIndex = account - 1;
 96
 197        if (_balance[balanceIndex] < money)
 098        {
 099            return false;
 100        }
 101
 1102        _balance[balanceIndex] -= money;
 103
 1104        return true;
 2105    }
 106}