add: 230301
This commit is contained in:
parent
acd093331d
commit
7a0acbf6a3
|
|
@ -0,0 +1,31 @@
|
|||
#include <vector>
|
||||
#include <cstdint>
|
||||
|
||||
/**
|
||||
* 912. Sort an Array
|
||||
*
|
||||
* Given an array of integers nums, sort the array in ascending order and return it.
|
||||
* You must solve the problem without using any built-in functions in O(nlog(n)) time complexity and with the smallest space complexity possible.
|
||||
*/
|
||||
|
||||
class Solution {
|
||||
private:
|
||||
static inline const int S = 50001;
|
||||
|
||||
public:
|
||||
static std::vector<int> sortArray(std::vector<int>& nums) {
|
||||
const int n = nums.size();
|
||||
std::vector<int> ret(n);
|
||||
uint16_t bucket[100005]{};
|
||||
for (int i : nums)
|
||||
++bucket[i + S];
|
||||
for (int i = 0, pos = 0; i < 100005; ++i)
|
||||
for (int j = 0, ins = i - S; j < bucket[i]; ++j)
|
||||
ret[pos++] = ins;
|
||||
return ret;
|
||||
}
|
||||
};
|
||||
|
||||
int main() {
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
CMAKE_MINIMUM_REQUIRED(VERSION 3.24)
|
||||
PROJECT(2303)
|
||||
|
||||
SET(CMAKE_CXX_STANDARD 23)
|
||||
|
||||
ADD_EXECUTABLE(2303 230301.cpp)
|
||||
|
|
@ -27,5 +27,6 @@ ADD_EXECUTABLE(leetcode-cpp main.cpp 2302/230218.cpp 2302/230218-CN.cpp 2302/230
|
|||
# ADD_SUBDIRECTORY(2206)
|
||||
# ADD_SUBDIRECTORY(2207)
|
||||
# ADD_SUBDIRECTORY(2210)
|
||||
ADD_SUBDIRECTORY(2302)
|
||||
# ADD_SUBDIRECTORY(2302)
|
||||
ADD_SUBDIRECTORY(2303)
|
||||
ADD_SUBDIRECTORY(more)
|
||||
|
|
|
|||
Loading…
Reference in New Issue