LeetCode-912.Sort an Array

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

排序

参考https://www.cnblogs.com/zhacai/p/11011961.html

原文地址:https://www.cnblogs.com/zhacai/p/11017408.html

时间: 2024-08-29 13:20:23

LeetCode-912.Sort an Array的相关文章

[LeetCode] 912. Sort an Array 数组排序

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 <= A.length <= 10000 -50000 <= A[i] <= 50000 Github 同步地址: https://g

Leetcode 360: Sort Transformed Array

Given a sorted array of integers nums and integer values a, b and c. Apply a quadratic function of the form f(x) = ax2 + bx + c to each element x in the array. The returned array must be in sorted order. Expected time complexity: O(n) Example: nums =

LeetCode 922 Sort Array By Parity II 解题报告

题目要求 Given an array A of non-negative integers, half of the integers in A are odd, and half of the integers are even. Sort the array so that whenever A[i] is odd, i is odd; and whenever A[i] is even, i is even. You may return any answer array that sa

【LeetCode】Sort Colors

LeetCode OJ Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue. Here, we will use the integers 0, 1, and 2 to represent the color red, w

[LeetCode OJ] Sort Colors

Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue. Here, we will use the integers 0, 1, and 2 to represent the color red, white, and bl

LeetCode | 1387. Sort Integers by The Power Value将整数按权重排序【Python】

LeetCode 1387. Sort Integers by The Power Value将整数按权重排序[Medium][Python][排序] Problem LeetCode The power of an integer x is defined as the number of steps needed to transform x into 1 using the following steps: if x is even then x = x / 2 if x is odd t

LeetCode --- 88. Merge Sorted Array

题目链接:Merge Sorted Array Given two sorted integer arrays A and B, merge B into A as one sorted array. Note: You may assume that A has enough space (size that is greater or equal to m + n) to hold additional elements from B. The number of elements init

LeetCode Insertion Sort List

class Solution { public: ListNode *insertionSortList(ListNode *head) { if (head == NULL) return NULL; ListNode* sorted_head = head; ListNode* unsorted_head = head->next; head->next = NULL; ListNode* cur = unsorted_head; while (cur != NULL) { unsorte

LeetCode OJ - Convert Sorted Array/List to Binary Search Tree

虚函数使用的时机 为什么虚函数不总是适用? 1. 虚函数有事会带来很大的消耗: 2. 虚函数不总是提供所需的行为: 3. 当我们不考虑继承当前类时,不必使用虚函数. 必须使用虚函数的情况: 1. 当你想删除一个表面上指向基类对象,实际却是指向派生类对象的指针,就需要虚析构函数. LeetCode OJ - Convert Sorted Array/List to Binary Search Tree,布布扣,bubuko.com LeetCode OJ - Convert Sorted Arra

Sort the Array

Being a programmer, you like arrays a lot. For your birthday, your friends have given you an array a consisting of n distinct integers. Unfortunately, the size of a is too small. You want a bigger array! Your friends agree to give you a bigger array,