AlgoFrames

Implement insertion sort

Standard · Write code · about 10 min

Sort nums in ascending order with insertion sort and return it. Sort in place: shift bigger values right instead of building a new array.

Example 1

Input:

[[5,2,4,6,1,3]]

Output:

[1,2,3,4,5,6]

Example 2

Input:

[[3,1,2]]

Output:

[1,2,3]

Constraints

  • 0 ≤ nums.length ≤ 1,000
  • -10,000 ≤ nums[i] ≤ 10,000

Learn the idea first: Insertion sort, a visual lesson.

More Insertion sort problems