自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(50)
  • 收藏
  • 关注

转载 leetcode 27. 移除元素 【时间击败100.00%】【内存击败84.67%】

1 public int removeElement(int[] nums, int val) { 2 int last = nums.length - 1; 3 for (int i = 0; i <= last && last >= 0; i++) { 4 while (last ...

2019-09-30 22:14:00 88

转载 Java 堆排序

1 public class HeapSort { 2 public static void main(String[] args) { 3 int[] a = new int[]{6, 2, 8, 3, 5, 1, 8, 6, 54, 64, -1, 2, 4, 4, 67}; 4 heapSort(a); 5 ...

2019-09-26 09:37:00 78

转载 牛客 二叉树中和为某一值的路径 【时间19ms】【内存9560k】

https://www.nowcoder.com/practice/b736e784e3e34731af99065031301bca构造函数:new ArrayList(al)把al的所有值复制到 new ArrayList()里,并且 new ArrayList()的值不会随着al的改变而改变。al0.addAll(al):当al的值改变,al0的值也随之改变。...

2019-09-25 23:29:00 84

转载 leetcode 98. 验证二叉搜索树 【一遍dfs】【时间击败99.72%】【内存击败94.23%】

复用left[],【时间击败73.33%】——》【时间击败99.72%】【内存击败36.17%】——》【内存击败94.23%】dfs(r)返回值=new long[]{包括r节点的子树所有节点的最小值,包括r节点的子树所有节点的最大值} 1 boolean ans = true; 2 3 public boolean isValid...

2019-09-25 17:03:00 76

转载 leetcode 94. 二叉树的中序遍历【时间击败99.19%】 【内存击败39.48%】

public List<Integer> inorderTraversal(TreeNode root) { ArrayList<Integer>al=new ArrayList<>(); if (root==null)return al; al.addAll(inorderTravers...

2019-09-25 11:53:00 45

转载 leetcode 814. 二叉树剪枝 【时间击败100.00%】【 内存击败84.62%】

1 public TreeNode pruneTree(TreeNode root) { 2 dfs(root,null,-1); 3 return root; 4 } 5 6 public void dfs(TreeNode cur, TreeNode fa, int left) { 7 ...

2019-09-25 11:35:00 50

转载 leetcode 655. 输出二叉树 【时间击败100.00%】 【内存击败96.49%】

1 public List<List<String>> printTree(TreeNode root) { 2 ArrayList<List<String>> al = new ArrayList<>(); 3 if (root == null) return al; 4 ...

2019-09-25 11:00:00 54

转载 leetcode 310. 最小高度树 【时间击败70.67%】 【内存击败89.04%】

数组替代队列,从超时到击败70%,用tree[0]替代new一个新的ArrayList,上升10%思想是遍历一遍,删除度为1的节点,答案只可能为1或2 1 public List<Integer> findMinHeightTrees(int n, int[][] edges) { 2 ArrayList<Integer...

2019-09-25 09:58:00 73

转载 leetcode 538. 把二叉搜索树转换为累加树 【时间击败100.00%】 【内存击败96.46%】...

因为二叉搜索树的左子树<根<右子树的性质,按right-root-left的顺序遍历很容易求出累加和 1 int add = 0; 2 3 public TreeNode convertBST(TreeNode root) { 4 if (root == null) return root; 5 ...

2019-09-24 11:35:00 409

转载 leetcode 100. 相同的树【 时间击败100.00%】 【内存击败83.99%】

1 public boolean isSameTree(TreeNode p, TreeNode q) { 2 if (p==null&&q==null)return true; 3 if (p==null||q==null)return false; 4 return check(p, q);...

2019-09-24 10:22:00 64

转载 leetcode 572. 另一个树的子树 【时间击败88.10%】 【内存击败96.40%】

1 boolean ans = false; 2 3 public boolean isSubtree(TreeNode s, TreeNode t) { 4 if (t == null) return true; 5 if (s == null) return false; 6 dfs(s, t)...

2019-09-24 10:16:00 46

转载 java中hashmap的实现原理

HashMap底层是一个数组,通过允许冲突来实现大小可扩充。数组的下标是对象的散列码,存储的是list,查询list的时候是线性equals()比较(所以速度的瓶颈在于不能让list过长,也就是数据不能太集中)。放入HashMap的对象要实现2个方法,hashCode()和equals()。equals()正确的实现必须满足5个条件:1、自反性:x.equals(x)必为tr...

2019-09-24 09:51:00 45

转载 Java的int和Integer

java里一切都是对象,对象=引用+对象本身。引用储存在堆栈(RAM)里,因为只有知道生命周期的数据才能存储在堆栈里,对象储存在堆里,因为堆不要求知道数据的生命周期。Java里所有的对象都储存在堆里,当你new的时候堆就会分配空间,但堆的分配和清理慢,如果对于小的简单的基本类型,用引用直接储存值,就可以创建在堆栈中。所以:1、Integer是一个对象,它等于引用+值,引用...

2019-09-23 21:12:00 83

转载 LeetCode 26. 删除排序数组中的重复项 【时间击败100.00%】 【内存击败95.37%】

1 public int removeDuplicates(int[] nums) { 2 //返回值len的长度用++方便,因为填充一个值可能删除很多值 3 //初始化为1,填充则len++ 4 int len = 1; 5 OUT: 6 for (int i = ...

2019-09-23 19:27:00 30

转载 LeetCode 25. K 个一组翻转链表 【时间击败99.35%】 【内存击败74.50%】

抱歉,我就是交换了值,用数组保存的,没想到过了 -3-…… 1 public ListNode reverseKGroup(ListNode head, int k) { 2 ListNode p = head, p2 = p; 3 int[]a=new int[k]; 4 5 if (p == n...

2019-09-23 18:53:00 47

转载 LeetCode 24. 两两交换链表中的节点 【时间击败100.00%】 【内存击败86.60%】

1 public ListNode swapPairs(ListNode head) { 2 if (head == null || head.next == null) return head; 3 ListNode a = head, b = head.next, c, last = null; 4 head...

2019-09-23 18:49:00 92

转载 LeetCode 23. 合并K个排序链表 【时间击败98.35%】 【内存击败94.11%】

原本是“逐一两两合并链表”,用时118ms,换成假分治后只用4ms,震惊!代码其实就是把遍历换成了队列……关键代码变化:“分治”:1 static public ListNode mergeKLists(ListNode[] lists) {2 if (lists == null || lists.length == 0) ret...

2019-09-23 18:17:00 53

转载 LeetCode 22. 括号生成 【时间击败42.92%】 【内存击败99.07%】

f(n)="("+f(n-1)+")  +f(i)f(n-i)  +f(n-i)f(i)举个例子:f(2)="("+f(1)+")"  +"()"f(1)  +f(1)"()" 1 import java.util.ArrayList; 2 import java.util.HashSet; 3 import java....

2019-09-23 17:31:00 67

转载 TCP/IP包

包是分组数据包的简称,分组数据包是分组交换协议的结果。分组交换协议就是规定一块大数据被分割成一个个更小的分组数据包,每一个被贴上报文头(包括源地址、目标地址、分组序号),依次传输给目标计算机,目标计算机接收到包后,丢掉报文头,通过报文头里的分组序号(是大块数据的第几个包)恢复完整的大块数据。包的首部除了必要的源地址和目标地址用来表示从这一层的什么地方传输到这一层的什么地方之外,...

2019-09-16 19:45:00 75

转载 TCP/IP层次模型

应用层:是【应用程序】实现的功能,如发送电子邮件的话,把文字用UTF-8编码、设定发送时间等功能都属于应用层,直到点击“发送——建立TCP连接,发送给传输层。传输层:利用TCP协议,将应用层传输过来的数据从一个【程序】发送至另一个计算机的程序里。通过在应用层传输过来的数据上添加一个TCP头,指明源端口号和目标端口号(端口号唯一标识程序,计算机用I...

2019-09-16 19:23:00 98

转载 C. Alyona and the Tree

http://codeforces.com/contest/682/problem/Cdfs,没什么好说的,直接看代码吧 1 import java.util.ArrayList; 2 import java.util.Scanner; 3 4 5 public class Main { 6 static long[] a =...

2019-08-28 16:21:00 106

转载 B. Alyona and Mex

http://codeforces.com/contest/682/problem/B1 //超时2 int[]a=new int[n];3 for (int i = 0; i < n; i++) a[i]=io.nextInt();4 Arrays.sort(a);5 ...

2019-08-28 12:56:00 171

转载 A. Alyona and Numbers

http://codeforces.com/contest/682/problem/A 1 import java.util.ArrayList; 2 import java.util.Scanner; 3 4 public class Main { 5 public static void main(String[] args) { 6...

2019-08-28 12:22:00 107

转载 D. New Year Santa Network

http://codeforces.com/contest/500/problem/Dhttps://blog.csdn.net/ShiAokai/article/details/42921885?locationNum=8&fps=1 1 import java.util.ArrayList; 2 import java.util.Scanne...

2019-08-28 12:07:00 46

转载 C. New Year Book Reading

http://codeforces.com/contest/500/problem/C模拟 1 import java.util.Scanner; 2 3 public class Main { 4 5 public static void main(String[] args) { 6 Scanner io ...

2019-08-26 11:50:00 119

转载 B. New Year Permutation

http://codeforces.com/contest/500/problem/B并查集 1 import java.util.Scanner; 2 3 public class Main { 4 static final int MAX = Integer.MAX_VALUE; 5 static int[] f = n...

2019-08-26 00:47:00 88

转载 A. New Year Transportation

http://codeforces.com/contest/500/problem/A 1 import java.util.Scanner; 2 3 public class Main { 4 static final int MAX = Integer.MAX_VALUE; 5 6 public static void ma...

2019-08-26 00:22:00 119

转载 D. The Child and Zoo

http://codeforces.com/contest/437/problem/D排序+并查集为了理解原理,让我们先画一个圈:其中红边无限大,黑边值为0我们可以发现,红边的值:1、直接就是f(1,2),2、毫不影响剩下的f(1,3)、f(1,4)、f(2,3)、f(2,4)、f(3,4)的值所以对应的,我们可以得出:1、当它是图里...

2019-08-25 23:53:00 120

转载 C. The Child and Toy

http://codeforces.com/contest/437/problem/C贪心,按照自身的费用从大到小拿,费用相等先后顺序不影响结果至于为什么嘛……试试这么想想,每一条边的消费是必算的,整个过程是拿点消边,最后图上是不存在边的。而每条边的消费又只有两种可能,那么拿消费大的点就是个最优解,保证所有牵连边消费都选择最小 1 impor...

2019-08-25 13:21:00 85

转载 B. The Child and Set

http://codeforces.com/contest/437/problem/B等差数列1 + 2*k的lowbit()为2^0等差数列2 + 4*k的lowbit()为2^1等差数列4 + 8*k的lowbit()为2^2等差数列8 + 16*k的lowbit()为2^3 1 import java.util.ArrayList; 2...

2019-08-24 16:50:00 108

转载 A. The Child and Homework

http://codeforces.com/contest/437/problem/A 1 import java.util.ArrayList; 2 import java.util.Scanner; 3 4 public class Main { 5 6 public static void main(String[] args) ...

2019-08-24 14:38:00 139

转载 F. Special Matrices

http://codeforces.com/contest/489/problem/Fhttp://blog.lightning34.cn/?p=107 1 public static void main(String[] args) { 2 n = io.nextInt(); 3 m = io.nextInt...

2019-08-17 18:29:00 141

转载 E. Hiking Dinkelbach

http://codeforces.com/contest/489/problem/Ehttps://www.cnblogs.com/KirisameMarisa/p/4187637.html 1 import java.util.Scanner; 2 3 import static java.lang.Math.abs; 4 impo...

2019-08-17 14:18:00 114

转载 D. Unbearable Controversy of Being

http://codeforces.com/contest/489/problem/D暴力,枚举所有"damn rhombus"对于任意a、c,设其a->i->c的路个数为cnt,其"damn rhombus"个数为cnt*(cnt-1)/2初始化cnt[][],然后遍历所有点即可 1 public class ...

2019-07-28 10:03:00 116

转载 C. Given Length and Sum of Digits...

http://codeforces.com/contest/489/problem/C大数就是从最高位,能大就大;小数就是从最低位,能小就小,再处理下最高位为0的情况。无结果无非一个sum太小,min全为0,一个sum太大,全为9还有剩 1 public class Main { 2 public static void main...

2019-07-27 23:09:00 173

转载 B. BerSU Ball

http://codeforces.com/contest/489/problem/B二分匹配模板题 1 public class Main { 2 static final int maxn = 2000; 3 static int n, m; 4 static int[] a = new int[maxn];...

2019-07-27 13:47:00 73

转载 A. SwapSort

http://codeforces.com/contest/489/problem/A看样例不难发现,对于i,找到 i<=j<=n-1里最小的数,若有与i交换 1 public static void main(String[] args) { 2 Scanner io = new Scanner(System.in)...

2019-07-27 11:20:00 103

转载 D. A Shade of Moonlight

http://codeforces.com/contest/989/problem/Demm……贪心吧。首先呢,那个月亮是一个点,并不是一个长度为1,在[-0.5,0.5]之间的线段,我被Note忽悠了思路:确保最后一个点消失时能被风吹到原点设下标为1的是从左往右,下标为2的是从右往左,最后一个点有方程式:s1+t=s2-t+l得t=(s2...

2019-07-26 17:54:00 132

转载 C. A Mist of Florescence

http://codeforces.com/contest/989/problem/C这磨人的小妖精……贪心,不难发现正确性,用一个A、B、C、D、分别哪拿一个出来画框,每一个框处理一种字母例如一个框长这样:加层后长这样:反正都只花费1个A处理字母后长这样:我用1个...

2019-07-26 10:12:00 111

转载 B. A Tide of Riverscape

http://codeforces.com/contest/989/problem/B思路还是从模拟开始。设前p个字符为p串,遍历p串的所有情况,然后对于剩下的字符,检查是否满足题目要求1、p串有2^2000种可能,数组保存不下所有情况,于是考虑深搜,也就是遇到'.',直接假设为0考虑下一个,不行的话函数返回考虑'1'2、对于例子2,我们发现p的...

2019-07-25 10:44:00 148

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除