随笔分类 -  sf

摘要:public List<List<Integer>> zigzagLevelOrder(TreeNode root) { List<List<Integer>> result = new LinkedList<>(); if (root == null) { return result; } // 阅读全文
posted @ 2021-01-05 10:26 soft.push("zzq") 阅读(271) 评论(0) 推荐(0)
摘要:一、朋友圈评论系统设计 A: {B, C, D} B: {A, D} 假设:A发表了一篇朋友圈文章,好友可以来评论 问题:表结构如何设计,评论插入和查询如何实现? 查询需要有主题:图片或文字; 1 先获取所有评论 2 显示评论时,获取好友关心决定是否进行展示。 评论表: user_id,topic 阅读全文
posted @ 2020-12-28 11:53 soft.push("zzq") 阅读(479) 评论(0) 推荐(0)
摘要:public static List<Integer> getVals(Node root){ List<Integer> ret=new ArrayList(); if(root == null) return ret; Queue<Node> qRet=new LinkedList(); qRe 阅读全文
posted @ 2020-12-24 19:53 soft.push("zzq") 阅读(173) 评论(0) 推荐(0)
摘要:public static int sqrt(int a) { if (a < 0 || a == 0 || a == 1) return a; int startNum = 0; int endNum = a; for (; startNum + 1 < endNum; ) {//保证整数情况下, 阅读全文
posted @ 2020-12-23 13:48 soft.push("zzq") 阅读(331) 评论(0) 推荐(0)
摘要:public void DFS(TreeNode root) {深度优先 Stack<TreeNode> stack = new Stack<>(); stack.add(root); while (!stack.isEmpty()) { // 移除最后一个 TreeNode tempNode = 阅读全文
posted @ 2020-12-22 14:37 soft.push("zzq") 阅读(338) 评论(0) 推荐(0)
摘要:public static void main(String[] args) { int[] m = {2, 4, 6, 9, 12, 13, 15, 16}; int[] n = {3, 5, 9, 12, 15}; Search(m, n); } private static void Sear 阅读全文
posted @ 2020-12-15 15:36 soft.push("zzq") 阅读(606) 评论(0) 推荐(0)
摘要:public Map<String, List<String>> getWordList(List<String> list) { Map<String, List<String>> ret = new HashMap<>(); for (int i = 0; i < list.size(); i+ 阅读全文
posted @ 2020-12-14 11:51 soft.push("zzq") 阅读(72) 评论(0) 推荐(0)
摘要:public static void main(String[] args) { Node n6 = new Node(6); Node n5 = new Node(5); n5.next = n6; Node n4 = new Node(4); n4.next = n5; Node n3 = ne 阅读全文
posted @ 2020-12-13 14:02 soft.push("zzq") 阅读(98) 评论(0) 推荐(0)
摘要:public static boolean sum2(int ary[], int sum) { int start = 0; int end = ary.length - 1; for (; start < end; ) { if (ary[start] + ary[end] == sum) { 阅读全文
posted @ 2020-12-11 18:42 soft.push("zzq") 阅读(113) 评论(0) 推荐(0)
摘要:public static void main(String[] args) { int ret = commpareStr("abc", "12345cab"); System.out.println(ret); } //orgStr源字段 public static int commpareSt 阅读全文
posted @ 2020-12-08 12:02 soft.push("zzq") 阅读(186) 评论(0) 推荐(0)
摘要:核心思想找一个轴点元素,备份轴点元素,先从右往左找,end--操作。一旦不满足大小条件,则将右侧的数值放置到开始位置,然后开始位置进行++,向右侧找进行循环往复 public static void main(String[] args) { int ary[] = {6, 8, 8, 6, 2, 阅读全文
posted @ 2020-10-22 11:05 soft.push("zzq") 阅读(231) 评论(0) 推荐(0)
摘要:public static void main(String[] args) { AtomicInteger a = new AtomicInteger(0); CountDownLatch countDownLatch = new CountDownLatch(1); Semaphore sema 阅读全文
posted @ 2020-10-20 21:15 soft.push("zzq") 阅读(394) 评论(1) 推荐(0)
摘要:import com.google.common.base.Charsets; import com.google.common.base.Joiner; import com.google.common.base.Predicate; import com.google.common.base.S 阅读全文
posted @ 2020-09-05 13:27 soft.push("zzq") 阅读(310) 评论(0) 推荐(0)
摘要:public ListNode getKthFromEnd(ListNode head, int k) { ListNode slow=head; ListNode fast=head; int t = 0; for(;fast!=null;){ if(t>=k) { slow=slow.next; 阅读全文
posted @ 2020-09-01 15:11 soft.push("zzq") 阅读(111) 评论(0) 推荐(0)
摘要:private boolean slowAndFastSolution(ListNode head) { if (head == null) { return false; } ListNode slow = head; ListNode fast = head.next; while (fast 阅读全文
posted @ 2020-08-30 12:57 soft.push("zzq") 阅读(89) 评论(0) 推荐(0)
摘要:public int add(int a, int b) { while (a != 0) { int temp = a ^ b; a = (a & b) << 1; b = temp; } return b; } 阅读全文
posted @ 2020-08-30 12:49 soft.push("zzq") 阅读(120) 评论(0) 推荐(0)
摘要:public int divide(int dividend, int divisor) { boolean sign = (dividend > 0) ^ (divisor > 0); int result = 0; if(dividend>0) { dividend = -dividend; } 阅读全文
posted @ 2020-08-30 12:46 soft.push("zzq") 阅读(208) 评论(0) 推荐(0)
摘要:public int divide(int dividend, int divisor) { //判断符号 int symbol=(dividend>0&&divisor>0)||(dividend<0&&divisor<0)?1:-1; //边界情况直接返回 if(dividend==Intege 阅读全文
posted @ 2020-08-30 12:44 soft.push("zzq") 阅读(176) 评论(0) 推荐(0)
摘要:public ListNode removeNthFromEnd(ListNode head, int n) { ListNode dummy = new ListNode(0); dummy.next = head; ListNode first = dummy; ListNode second 阅读全文
posted @ 2020-08-30 10:07 soft.push("zzq") 阅读(86) 评论(0) 推荐(0)
摘要:public ListNode mergeTwoLists(ListNode l1, ListNode l2) { if(l1 == null) { return l2; } if(l2 == null) { return l1; } if(l1.val < l2.val) { l1.next = 阅读全文
posted @ 2020-08-29 22:36 soft.push("zzq") 阅读(134) 评论(0) 推荐(0)