Refactor structure

This commit is contained in:
Sainnhe Park 2023-01-30 20:17:47 +08:00
parent 606185176c
commit 038fa42883
12 changed files with 47 additions and 70 deletions

View File

@ -1,13 +1,7 @@
#ifndef S0002_ADD_TWO_NUMBERS_HPP #ifndef S0002_ADD_TWO_NUMBERS_HPP
#define S0002_ADD_TWO_NUMBERS_HPP #define S0002_ADD_TWO_NUMBERS_HPP
struct ListNode { #include "structures.hpp"
int val;
ListNode* next;
ListNode() : val(0), next(nullptr) {}
ListNode(int x) : val(x), next(nullptr) {}
ListNode(int x, ListNode* next) : val(x), next(next) {}
};
class S0002 { class S0002 {
public: public:

View File

@ -1,13 +1,7 @@
#ifndef S0019_REMOVE_NTH_NODE_FROM_END_OF_LIST_HPP #ifndef S0019_REMOVE_NTH_NODE_FROM_END_OF_LIST_HPP
#define S0019_REMOVE_NTH_NODE_FROM_END_OF_LIST_HPP #define S0019_REMOVE_NTH_NODE_FROM_END_OF_LIST_HPP
struct ListNode { #include "structures.hpp"
int val;
ListNode* next;
ListNode() : val(0), next(nullptr) {}
ListNode(int x) : val(x), next(nullptr) {}
ListNode(int x, ListNode* next) : val(x), next(next) {}
};
class S0019 { class S0019 {
public: public:

View File

@ -3,15 +3,9 @@
#include <limits> #include <limits>
using namespace std; #include "structures.hpp"
struct ListNode { using namespace std;
int val;
ListNode* next;
ListNode() : val(0), next(nullptr) {}
ListNode(int x) : val(x), next(nullptr) {}
ListNode(int x, ListNode* next) : val(x), next(next) {}
};
class S0021 { class S0021 {
public: public:

View File

@ -3,15 +3,9 @@
#include <vector> #include <vector>
using namespace std; #include "structures.hpp"
struct ListNode { using namespace std;
int val;
ListNode *next;
ListNode() : val(0), next(nullptr) {}
ListNode(int x) : val(x), next(nullptr) {}
ListNode(int x, ListNode *next) : val(x), next(next) {}
};
class S0023 { class S0023 {
public: public:

View File

@ -1,13 +1,7 @@
#ifndef S0024_SWAP_NODES_IN_PAIRS_HPP #ifndef S0024_SWAP_NODES_IN_PAIRS_HPP
#define S0024_SWAP_NODES_IN_PAIRS_HPP #define S0024_SWAP_NODES_IN_PAIRS_HPP
struct ListNode { #include "structures.hpp"
int val;
ListNode* next;
ListNode() : val(0), next(nullptr) {}
ListNode(int x) : val(x), next(nullptr) {}
ListNode(int x, ListNode* next) : val(x), next(next) {}
};
class S0024 { class S0024 {
public: public:

View File

@ -4,15 +4,9 @@
#include <tuple> #include <tuple>
#include <utility> #include <utility>
using namespace std; #include "structures.hpp"
struct ListNode { using namespace std;
int val;
ListNode* next;
ListNode() : val(0), next(nullptr) {}
ListNode(int x) : val(x), next(nullptr) {}
ListNode(int x, ListNode* next) : val(x), next(next) {}
};
class S0025 { class S0025 {
public: public:

View File

@ -3,11 +3,7 @@
#include <unordered_map> #include <unordered_map>
struct ListNode { #include "structures.hpp"
int val;
ListNode* next;
ListNode(int x) : val(x), next(nullptr) {}
};
struct IterResult { struct IterResult {
ListNode *node; ListNode *node;
@ -17,7 +13,7 @@ struct IterResult {
class S0142 { class S0142 {
public: public:
std::unordered_map<ListNode *, int> footprint; std::unordered_map<ListNode *, int> footprint;
IterResult iter(ListNode *fast, ListNode* slow, bool startUp); IterResult iter(ListNode *fast, ListNode *slow, bool startUp);
ListNode *detectCycle(ListNode *head); ListNode *detectCycle(ListNode *head);
}; };

View File

@ -1,11 +1,7 @@
#ifndef S0160_INTERSECTION_OF_TWO_LINKED_LISTS_HPP #ifndef S0160_INTERSECTION_OF_TWO_LINKED_LISTS_HPP
#define S0160_INTERSECTION_OF_TWO_LINKED_LISTS_HPP #define S0160_INTERSECTION_OF_TWO_LINKED_LISTS_HPP
struct ListNode { #include "structures.hpp"
int val;
ListNode *next;
ListNode(int x) : val(x), next(nullptr) {}
};
class S0160 { class S0160 {
public: public:

View File

@ -1,13 +1,7 @@
#ifndef S0203_REMOVE_LINKED_LIST_ELEMENTS_HPP #ifndef S0203_REMOVE_LINKED_LIST_ELEMENTS_HPP
#define S0203_REMOVE_LINKED_LIST_ELEMENTS_HPP #define S0203_REMOVE_LINKED_LIST_ELEMENTS_HPP
struct ListNode { #include "structures.hpp"
int val;
ListNode* next;
ListNode() : val(0), next(nullptr) {}
ListNode(int x) : val(x), next(nullptr) {}
ListNode(int x, ListNode* next) : val(x), next(next) {}
};
class S0203 { class S0203 {
public: public:

View File

@ -1,13 +1,7 @@
#ifndef S0206_REVERSE_LINKED_LIST_HPP #ifndef S0206_REVERSE_LINKED_LIST_HPP
#define S0206_REVERSE_LINKED_LIST_HPP #define S0206_REVERSE_LINKED_LIST_HPP
struct ListNode { #include "structures.hpp"
int val;
ListNode* next;
ListNode() : val(0), next(nullptr) {}
ListNode(int x) : val(x), next(nullptr) {}
ListNode(int x, ListNode* next) : val(x), next(next) {}
};
class S0206 { class S0206 {
public: public:

View File

@ -0,0 +1,11 @@
#ifndef S0226_INVERT_BINARY_TREE_HPP
#define S0226_INVERT_BINARY_TREE_HPP
#include "structures.hpp"
class S0226 {
public:
TreeNode* invertTree(TreeNode* root);
};
#endif

22
include/structures.hpp Normal file
View File

@ -0,0 +1,22 @@
#ifndef STRUCTURES_HPP
#define STRUCTURES_HPP
struct ListNode {
int val;
ListNode *next;
ListNode() : val(0), next(nullptr) {}
ListNode(int x) : val(x), next(nullptr) {}
ListNode(int x, ListNode *next) : val(x), next(next) {}
};
struct TreeNode {
int val;
TreeNode *left;
TreeNode *right;
TreeNode() : val(0), left(nullptr), right(nullptr) {}
TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
TreeNode(int x, TreeNode *left, TreeNode *right)
: val(x), left(left), right(right) {}
};
#endif