From 7a0acbf6a388fcbef0f153a9dd3f8f56d1bfe2b6 Mon Sep 17 00:00:00 2001 From: Eatswap Date: Wed, 1 Mar 2023 12:12:50 +0800 Subject: [PATCH] add: 230301 --- cpp/2303/230301.cpp | 31 +++++++++++++++++++++++++++++++ cpp/2303/CMakeLists.txt | 6 ++++++ cpp/CMakeLists.txt | 3 ++- 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 cpp/2303/230301.cpp create mode 100644 cpp/2303/CMakeLists.txt diff --git a/cpp/2303/230301.cpp b/cpp/2303/230301.cpp new file mode 100644 index 0000000..5cda7c3 --- /dev/null +++ b/cpp/2303/230301.cpp @@ -0,0 +1,31 @@ +#include +#include + +/** + * 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 sortArray(std::vector& nums) { + const int n = nums.size(); + std::vector 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; +} diff --git a/cpp/2303/CMakeLists.txt b/cpp/2303/CMakeLists.txt new file mode 100644 index 0000000..ecd3673 --- /dev/null +++ b/cpp/2303/CMakeLists.txt @@ -0,0 +1,6 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 3.24) +PROJECT(2303) + +SET(CMAKE_CXX_STANDARD 23) + +ADD_EXECUTABLE(2303 230301.cpp) diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index a1b133b..b55c4f3 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -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)