www

导航

2019年2月26日 #

二叉树中和为某一值的路径

摘要: public class Solution { ArrayList> res = new ArrayList(); ArrayList path = new ArrayList(); public ArrayList> FindPath(TreeNode root,int target) { if (root == null) { ... 阅读全文

posted @ 2019-02-26 22:59 www_practice 阅读(133) 评论(0) 推荐(0) 编辑

tcp面试题

摘要: 常见面试题【问题1】为什么连接的时候是三次握手,关闭的时候却是四次握手? 答:因为当Server端收到Client端的SYN连接请求报文后,可以直接发送SYN+ACK报文。其中ACK报文是用来应答的,SYN报文是用来同步的。但是关闭连接时,当Server端收到FIN报文时,很可能并不会立即关闭SOC 阅读全文

posted @ 2019-02-26 20:42 www_practice 阅读(467) 评论(0) 推荐(0) 编辑

2019年2月25日 #

从上往下打印二叉树

摘要: public ArrayList PrintFromTopToBottom(TreeNode root) { ArrayList ret = new ArrayList(); if(root==null) return ret; Queue queue = new LinkedList(); queue.offer(root); while(queue.s... 阅读全文

posted @ 2019-02-25 23:20 www_practice 阅读(129) 评论(0) 推荐(0) 编辑

合并两个排序链表

摘要: public ListNode Merge(ListNode list1,ListNode list2) { if(list1==null) return list2; if(list2==null) return list1; ListNode head=new ListNode(0); ListNode current = head; ... 阅读全文

posted @ 2019-02-25 22:58 www_practice 阅读(106) 评论(0) 推荐(0) 编辑

反转链表

摘要: public ListNode ReverseList(ListNode head) { if(head==null||head.next==null) return head; ListNode pReverseHead=null; ListNode pNode=head; ListNode pPrev=null; while... 阅读全文

posted @ 2019-02-25 21:06 www_practice 阅读(165) 评论(0) 推荐(0) 编辑

二进制中1的个数

摘要: public int NumberOf1(int n) { int count = 0; while (n!=0) { n = n&(n-1); count++; } return count; } 阅读全文

posted @ 2019-02-25 20:47 www_practice 阅读(93) 评论(0) 推荐(0) 编辑

链表中倒数第k个结点

摘要: public ListNode FindKthToTail(ListNode head,int k) { if(head==null) return head; ListNode pre=head; ListNode last=head; for(int i=0; i<k; i++){ if(last==null) return null; ... 阅读全文

posted @ 2019-02-25 20:45 www_practice 阅读(128) 评论(0) 推荐(0) 编辑

调整数组顺序使奇数位于偶数前面

摘要: public void reOrderArray(int [] array) { if(array==null||array.length==0) return; int start=0, end=array.length-1; while(startstart&&array[end]%2!=0) end--; if(start<end){ ... 阅读全文

posted @ 2019-02-25 19:22 www_practice 阅读(126) 评论(0) 推荐(0) 编辑

重建二叉树

摘要: public TreeNode reConstructBinaryTree(int [] pre,int [] in) { if(pre==null||in==null||pre.length!=in.length||pre.lengthpe || is>ie) return null; int val = pre[ps]; int ind... 阅读全文

posted @ 2019-02-25 19:10 www_practice 阅读(123) 评论(0) 推荐(0) 编辑

旋转数组的最小数字

摘要: public int minNumberInRotateArray(int [] array) { if(array==null||array.length==0) return -1; int start=0, end=array.length-1; int mid=start; while(array[start]>=arra... 阅读全文

posted @ 2019-02-25 18:59 www_practice 阅读(142) 评论(0) 推荐(0) 编辑