This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <queue> | |
| using namespace std; | |
| enum Color { RED, BLACK }; | |
| struct Node { | |
| char val; | |
| Color color; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| using namespace std; | |
| struct TreeNode { | |
| int start; | |
| int end; | |
| int sum; // or max/min | |
| TreeNode *left; | |
| TreeNode *right; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class BaseController { | |
| constructor () { | |
| this.ctx = { | |
| status: 200, | |
| body: {} | |
| }; | |
| const before = this.before || (() => { | |
| console.log(`Before run`); | |
| return true; | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ----------- adapter pattern ------------------- | |
| public class TargetA | |
| { | |
| public void Start() { ... } | |
| public void End() { ... } | |
| } | |
| public class TargetB | |
| { | |
| public void Begin() { ... } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <vector> | |
| #include <iostream> | |
| using namespace std; | |
| vector<int> dijkstra(vector<vector<pair<int, int>>>& graph) { | |
| vector<int> record(graph.size(), INT_MAX); | |
| vector<bool> visited(graph.size(), false); | |
| int curr = 0; | |
| record[curr] = 0; | |
| for (int i = 0; i < graph.size() - 1; i++) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <vector> | |
| #include <queue> | |
| #include <iostream> | |
| #include <stdexcept> | |
| using namespace std; | |
| // bellman ford's algorithm is an algorithm that finds shortest path | |
| // unlike dijkstra's algorithm, it also works while the cost is negative. | |
| // the time complexity is O(V·E) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <vector> | |
| using namespace std; | |
| class Disjoint_set { | |
| private: | |
| // the max depth of the tree depth | |
| vector<int> _rank; | |
| // the parent of the each node | |
| vector<int> _parent; | |
| public: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func (c *conn) serve(ctx context.Context) |
NewerOlder