← Practice · Backtracking

Permutations Medium

Given an array nums of distinct integers, return all possible permutations in any order.

Examples

  • nums = [0,1] -> [[0,1],[1,0]]
  • nums = [1] -> [[1]]

Define a function named permute in JavaScript.

00:00▶ Visualize

JavaScript · Tab indents · Ctrl/⌘+Enter runs the tests