< 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
94%
Covered lines: 35
Uncovered lines: 2
Coverable lines: 37
Total lines: 106
Line coverage: 94.5%
Branch coverage
83%
Covered branches: 10
Total branches: 12
Branch coverage: 83.3%
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(...)83.33%66100%
Deposit(...)50%2275%
Withdraw(...)100%44100%

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>
 525    public SimpleBankSystemLookup(long[] balance)
 526    {
 527        _balance = balance;
 528        _balanceLength = balance.Length;
 529    }
 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)
 540    {
 541        if (account1 > _balanceLength || account2 > _balanceLength)
 142        {
 143            return false;
 44        }
 45
 446        var balance1Index = account1 - 1;
 447        var balance2Index = account2 - 1;
 48
 449        if (_balance[balance1Index] < money)
 250        {
 251            return false;
 52        }
 53
 254        _balance[balance1Index] -= money;
 255        _balance[balance2Index] += money;
 56
 257        return true;
 558    }
 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)
 368    {
 369        if (account > _balanceLength)
 070        {
 071            return false;
 72        }
 73
 374        var balanceIndex = account - 1;
 75
 376        _balance[balanceIndex] += money;
 77
 378        return true;
 379    }
 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)
 789    {
 790        if (account > _balanceLength)
 191        {
 192            return false;
 93        }
 94
 695        var balanceIndex = account - 1;
 96
 697        if (_balance[balanceIndex] < money)
 398        {
 399            return false;
 100        }
 101
 3102        _balance[balanceIndex] -= money;
 103
 3104        return true;
 7105    }
 106}