add: 230301

This commit is contained in:
Eatswap 2023-03-01 12:12:50 +08:00
parent acd093331d
commit 7a0acbf6a3
Signed by: Eatswap
GPG Key ID: BE661106A1F3FA0B
3 changed files with 39 additions and 1 deletions

31
cpp/2303/230301.cpp Normal file
View File

@ -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;
}

6
cpp/2303/CMakeLists.txt Normal file
View File

@ -0,0 +1,6 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.24)
PROJECT(2303)
SET(CMAKE_CXX_STANDARD 23)
ADD_EXECUTABLE(2303 230301.cpp)

View File

@ -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)