Leetcode: Sort an Array

Sort an Array



Similar Problems:


Given an array of integers nums, sort the array in ascending order.

Example 1:

Input: [5,2,3,1]
Output: [1,2,3,5]

Example 2:

Input: [5,1,1,2,0,0]
Output: [0,0,1,1,2,5]

Note:

  1. 1 <= A.length <= 10000
  2. -50000 <= A[i] <= 50000

Github: code.dennyzhang.com

Credits To: leetcode.com

Leave me comments, if you have better ways to solve.


  • Solution:
// Blog link: https://code.dennyzhang.com/sort-an-array
// Basic Ideas: quicksort
// Complexity: Time O(1), Space (1)
import "sort"
func sortArray(nums []int) []int {
    sort.Ints(nums)
    return nums
}
linkedin
github
slack

Share It, If You Like It.

Leave a Reply

Your email address will not be published.