Skip to content

solve: 46.Permutations#50

Open
t9a-dev wants to merge 1 commit intomainfrom
46.Permutations
Open

solve: 46.Permutations#50
t9a-dev wants to merge 1 commit intomainfrom
46.Permutations

Conversation

@t9a-dev
Copy link
Owner

@t9a-dev t9a-dev commented Jan 29, 2026

問題: 46. Permutations
次に解く問題: 78. Subsets
ファイルの構成: ./src/bin/<各ステップ>.rs

/*
n = nums.len()
時間計算量: O(n!)
空間計算量: O(n!)

Choose a reason for hiding this comment

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

最終的に長さ n のpermutationを n! 個保持する必要があるため、空間計算量は O(n * n!) だと思います (が、自信はありません😓)

}

for i in swap_index..nums_len {
permutation.swap(swap_index, i);

Choose a reason for hiding this comment

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

前の方は確定済み、後ろの方は未確定という状態なので、permutationの代わりにprefix_and_remainingなどとするのも一つの案かもしれません。

fn make_permutations(
mut nums: VecDeque<i32>,
permutation: Vec<i32>,
permutatioins: &mut Vec<Vec<i32>>,
Copy link

Choose a reason for hiding this comment

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

nit: permutations

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants