摘要:
class Solution {public: ListNode *rotateRight(ListNode *head, int k) { if (head == NULL) return NULL; ListNode *p = head, *q = head; ... 阅读全文
摘要:
class Solution {public: int divide(int dividend, int divisor) { bool aneg = dividend a || a == 0) return 0; unsigned int abits = 0, ... 阅读全文
摘要:
class Solution {public: vector > threeSum(vector &num) { vector > res; int len = num.size(); sort(num.begin(), num.end()); ... 阅读全文
摘要:
先来一个暴力解:class Solution {public: vector > fourSum(vector &num, int target) { vector > res; vector r; r.resize(4); sort(n... 阅读全文
摘要:
class UnionFindSet { private: int *pref; int *rank; int capacity; public: UnionFindSet(int n) { if (n = c... 阅读全文
摘要:
#include #include #include #include using namespace std;typedef pair P;int main() { // zero means no connection int graph[5][5] = { ... 阅读全文
摘要:
单源最短路径算法Bellman-ford练习,可以处理有负边的情况(也可以在存在负圈时及时终止)#include #include #include using namespace std;class Edge {public: int from; int to; int cost... 阅读全文
摘要:
#include #include using namespace std;class BinaryIndexedTree {private: int *mem; int capacity;public: BinaryIndexedTree (int n) { if ... 阅读全文