chore: big refactor

This commit is contained in:
Eatswap 2023-05-02 09:33:39 +08:00
parent 586ed15310
commit e4093d32fd
Signed by: Eatswap
GPG Key ID: BE661106A1F3FA0B
5 changed files with 34 additions and 6 deletions

View File

@ -4,4 +4,6 @@ PROJECT(2305)
SET(CMAKE_CXX_STANDARD 23) SET(CMAKE_CXX_STANDARD 23)
SET(CMAKE_EXPORT_COMPILE_COMMANDS true) SET(CMAKE_EXPORT_COMPILE_COMMANDS true)
ADD_EXECUTABLE(2305 230501.cpp) FILE(GLOB src *.cpp)
ADD_EXECUTABLE(2305 ${src})

View File

@ -9,12 +9,12 @@
* Return the average salary of employees excluding the minimum and maximum salary. Answers within 1e-5 of the actual answer will be accepted. * Return the average salary of employees excluding the minimum and maximum salary. Answers within 1e-5 of the actual answer will be accepted.
*/ */
class Solution { class LC230501 {
public: public:
static inline double average(const std::vector<int>&) noexcept; static double average(const std::vector<int>&) noexcept;
}; };
inline double Solution::average(const std::vector<int>& salary) noexcept { double LC230501::average(const std::vector<int>& salary) noexcept {
return ( return (
std::reduce(salary.begin(), salary.end(), 0.0) - std::reduce(salary.begin(), salary.end(), 0.0) -
*std::min_element(salary.begin(), salary.end()) - *std::min_element(salary.begin(), salary.end()) -

View File

@ -13,13 +13,13 @@
* Return the number of minutes needed to inform all the employees about the urgent news. * Return the number of minutes needed to inform all the employees about the urgent news.
*/ */
class Solution { class LC230501CN {
public: public:
using CVIR = const std::vector<int>&; using CVIR = const std::vector<int>&;
static int numOfMinutes(int, int, CVIR, CVIR); static int numOfMinutes(int, int, CVIR, CVIR);
}; };
int Solution::numOfMinutes(int n, int headID, CVIR manager, CVIR informTime) { int LC230501CN::numOfMinutes(int n, int headID, CVIR manager, CVIR informTime) {
std::vector<int> ans(n, -1); std::vector<int> ans(n, -1);
ans[headID] = 0; ans[headID] = 0;
std::function<int(int)> dp = [&](int cur) { std::function<int(int)> dp = [&](int cur) {

17
cpp/2305/defs.h Normal file
View File

@ -0,0 +1,17 @@
#ifndef LEETCODE_CPP_DEFS_H
#define LEETCODE_CPP_DEFS_H
#include <vector>
class LC230501CN {
public:
using CVIR = const std::vector<int>&;
static int numOfMinutes(int, int, CVIR, CVIR);
};
class LC230501 {
public:
static double average(const std::vector<int>&) noexcept;
};
#endif //LEETCODE_CPP_DEFS_H

9
cpp/2305/main.cpp Normal file
View File

@ -0,0 +1,9 @@
#include <iostream>
#include "defs.h"
int main() {
std::cout << LC230501::average({1, 2, 3, 4}) << std::endl;
std::cout << LC230501CN::numOfMinutes(1, 0, {-1}, {0}) << std::endl;
return 0;
}