2018-09-13 10:48 public class Solution { public boolean isValidBST(TreeNode root) { return valid(root, Long.MIN_VALUE, Long.MAX_VALUE); } public boolean valid(TreeNode root, long low, long high) { if (root == null) return true; if (root.val <= low || root.val >= high) return false; return valid(root.left, low, root.val) && valid(root.right, root.val, high); } }
List<Map.Entry<String, String>> list = new ArrayList<>(map.entrySet()); Collections.sort(list, Comparator.comparing(Map.Entry::getValue)); 反转排序 list.sort(Comparator.comparing(Map.Entry<Long,String>::getValue).reversed()); 或者 list.sort(Collections.reverseOrder(Comparator.comparing(Map.Entry::getValue)));
public ListNode reverseList(ListNode head) { ListNode pre = null; ListNode next = null; while (head != null) { next = head.next; head.next = pre; pre = head; head = next; } return pre; }
各种SQL性能优化措施:消除慢查询、分表分库、索引、优化数据结构、限制搜索率
分布式缓存 读写分离 分库分表