摘要:
二叉树深度遍历 中序遍历 public List<Integer> inorderTraversal(TreeNode root) { //创建一个答案数组 List<Integer> ans = new ArrayList<>(); //创建一个双向链表,用作栈 Deque<TreeNode> s 阅读全文
摘要:
快速排序 双指针 分治 void quick_sort(int q[], int l, int r) { //递归的终止情况 if(l >= r) return; //第一步:分成子问题 int i = l - 1, j = r + 1, x = q[l + r >> 1]; while(i < j 阅读全文
摘要:
首先利用结构体存边,排序(快排,或者建堆),遍历所有边,利用并查集判断边两个端点是否在同一个集合中。 acwing-859 #include<bits/stdc++.h> using namespace std; const int N = 100010; struct edge{ int a, b 阅读全文