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
#define S0002_ADD_TWO_NUMBERS_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) {}
};
#include "structures.hpp"
class S0002 {
public:

View File

@ -1,13 +1,7 @@
#ifndef S0019_REMOVE_NTH_NODE_FROM_END_OF_LIST_HPP
#define S0019_REMOVE_NTH_NODE_FROM_END_OF_LIST_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) {}
};
#include "structures.hpp"
class S0019 {
public:

View File

@ -3,15 +3,9 @@
#include <limits>
using namespace std;
#include "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) {}
};
using namespace std;
class S0021 {
public:

View File

@ -3,15 +3,9 @@
#include <vector>
using namespace std;
#include "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) {}
};
using namespace std;
class S0023 {
public:

View File

@ -1,13 +1,7 @@
#ifndef S0024_SWAP_NODES_IN_PAIRS_HPP
#define S0024_SWAP_NODES_IN_PAIRS_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) {}
};
#include "structures.hpp"
class S0024 {
public:

View File

@ -4,15 +4,9 @@
#include <tuple>
#include <utility>
using namespace std;
#include "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) {}
};
using namespace std;
class S0025 {
public:

View File

@ -3,11 +3,7 @@
#include <unordered_map>
struct ListNode {
int val;
ListNode* next;
ListNode(int x) : val(x), next(nullptr) {}
};
#include "structures.hpp"
struct IterResult {
ListNode *node;
@ -17,7 +13,7 @@ struct IterResult {
class S0142 {
public:
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);
};

View File

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

View File

@ -1,13 +1,7 @@
#ifndef S0203_REMOVE_LINKED_LIST_ELEMENTS_HPP
#define S0203_REMOVE_LINKED_LIST_ELEMENTS_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) {}
};
#include "structures.hpp"
class S0203 {
public:

View File

@ -1,13 +1,7 @@
#ifndef S0206_REVERSE_LINKED_LIST_HPP
#define S0206_REVERSE_LINKED_LIST_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) {}
};
#include "structures.hpp"
class S0206 {
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