Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 0 additions & 38 deletions src/Bank2043.java

This file was deleted.

41 changes: 41 additions & 0 deletions src/main/java/com/leetcode/medium/Bank2043.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Tags: Array, Design
package com.leetcode.medium;

public class Bank2043 {
private final long[] accounts;

public Bank2043(long[] balance) {
accounts = balance;
}

public boolean transfer(int account1, int account2, long money) {
if (account1 > accounts.length || account2 > accounts.length) {
return false;
}
Comment on lines +12 to +14

Copilot AI Jan 11, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The account validation is incomplete. It only checks if the account number exceeds the array length, but doesn't validate if the account number is less than 1. Account numbers should be valid positive integers (1-indexed). Add a check for account1 < 1 || account2 < 1 to prevent potential ArrayIndexOutOfBoundsException when accessing accounts[account1 - 1] or accounts[account2 - 1].

Copilot uses AI. Check for mistakes.
if (accounts[account1 - 1] < money) {
return false;
}
accounts[account1 - 1] -= money;
accounts[account2 - 1] += money;
return true;
}

public boolean deposit(int account, long money) {
if (account > accounts.length) {
return false;
Comment on lines +24 to +25

Copilot AI Jan 11, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The account validation is incomplete. It only checks if the account number exceeds the array length, but doesn't validate if the account number is less than 1. Account numbers should be valid positive integers (1-indexed). Add a check for account < 1 to prevent potential ArrayIndexOutOfBoundsException when accessing accounts[account - 1].

Copilot uses AI. Check for mistakes.
}
accounts[account - 1] += money;
return true;
}

public boolean withdraw(int account, long money) {
if (account > accounts.length) {
return false;
Comment on lines +32 to +33

Copilot AI Jan 11, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The account validation is incomplete. It only checks if the account number exceeds the array length, but doesn't validate if the account number is less than 1. Account numbers should be valid positive integers (1-indexed). Add a check for account < 1 to prevent potential ArrayIndexOutOfBoundsException when accessing accounts[account - 1].

Copilot uses AI. Check for mistakes.
}
if (accounts[account - 1] < money) {
return false;
}
accounts[account - 1] -= money;
return true;
}
}
Loading
Loading