Skip to content

style: use for-of #241

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 6, 2024
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
10 changes: 5 additions & 5 deletions dynamic_programming/coin_change.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ export const coinChange = (money: number, coins: number[]): CoinChange => {
minCoins[0] = 0

// Fill in the DP table
for (let i = 0; i < coins.length; i++) {
for (const coin of coins) {
for (let j = 0; j <= money; j++) {
if (j >= coins[i]) {
if (minCoins[j] > 1 + minCoins[j - coins[i]]) {
minCoins[j] = 1 + minCoins[j - coins[i]]
lastCoin[j] = coins[i]
if (j >= coin) {
if (minCoins[j] > 1 + minCoins[j - coin]) {
minCoins[j] = 1 + minCoins[j - coin]
lastCoin[j] = coin
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions graph/prim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ const add_children = (
priorityQueue: PriorityQueue<Edge>,
node: number
) => {
for (let i = 0; i < graph[node].length; ++i) {
const out_edge = graph[node][i]
for (const out_edge of graph[node]) {
// By increasing the priority, we ensure we only add each vertex to the queue one time, and the queue will be at most size V.
priorityQueue.increasePriority(
out_edge[0],
Expand Down
2 changes: 1 addition & 1 deletion sorts/counting_sort.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const countingSort = (inputArr: number[], min: number, max: number) => {

const count = new Array(max - min + 1).fill(0)

for (let i = 0; i < inputArr.length; i++) count[inputArr[i] - min]++
for (const element of inputArr) count[element - min]++

count[0] -= 1

Expand Down
Loading