1 """ 2 Given a binary tree, return the inorder traversal of its nodes' values. 3 Example: 4 Input: [1,null,2,3] 5 1 6 \ 7 2 8 / 9 3 10 Output: [1,3,2 ...
分类:
其他好文 时间:
2020-02-13 22:54:06
阅读次数:
53
1 """ 2 Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree. 3 According to the definition of LCA on Wikipedia: ...
分类:
其他好文 时间:
2020-02-13 22:33:56
阅读次数:
67
Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists. Example: ...
分类:
其他好文 时间:
2020-02-13 20:46:21
阅读次数:
72
并查集算连通块的数量,集合的个数就是必然不开心的人数,再跑bfs,用优先队列维护~ #include<bits/stdc++.h> using namespace std; const int maxn=1e6+14; vector<int> g[maxn]; int father[maxn]; i ...
分类:
其他好文 时间:
2020-02-13 19:20:12
阅读次数:
48
1 function swap(&$arr, $a, $b){ 2 $temp = $arr[$a]; 3 $arr[$a] = $arr[$b]; 4 $arr[$b] = $temp; 5 } 6 冒泡排序 7 //沉底法 8 function bubbleSort($arr){ 9 $flag ...
分类:
编程语言 时间:
2020-02-13 19:08:07
阅读次数:
70
题目: 编写一个模板函数 fill,给数组a[start : end - 1]赋值 value。测试你的代码。 思路: 正常思路即可。当 start > end 时,进行交换,利用一下 new_swap() 函数。 代码: 1 #include <iostream> 2 using namespac ...
分类:
编程语言 时间:
2020-02-13 14:39:51
阅读次数:
87
You are given two integer arrays nums1 and nums2 sorted in ascending order and an integer k. Define a pair (u,v) which consists of one element from th ...
分类:
其他好文 时间:
2020-02-13 13:22:48
阅读次数:
67
Rikka with K Match Yuta has a graph $G$ with $n$ nodes $(i,j)(1 \leq i \leq n,1 \leq j \leq m)$. There is an edge between $(a,b)$ and $(c,d)$ if and o ...
分类:
其他好文 时间:
2020-02-13 12:48:35
阅读次数:
76
题目: 解释为什么下面程序的交换函数没有把形参 x 和 y 所对应的实参的值交换。如何修改代码,使实参的值得到交换? 原交换程序: 1 void swap(int x, int y) { 2 int temp = x; 3 x = y; 4 y = temp; 5 } 思路: 在C++中,参数传递方 ...
分类:
其他好文 时间:
2020-02-13 12:45:32
阅读次数:
69
tips: 1.注意边界处理,避免出现死循环 785. 快速排序 /* eg:2 1 2 用i则不能取到左边界,把x取值改成向上取整 用j则不能取到右边界,把x取值改成向下取整 取到边界会导致递归死循环 */ #include<iostream> #include<cstdio> using nam ...
分类:
其他好文 时间:
2020-02-12 21:57:31
阅读次数:
71