摘要:
440. 字典序的第K小數字 在0~9的字典樹(十叉樹)上,首先計算以 cur 為前綴的小于等于n的節點個數有多少,即通過以 cur 為根找子樹中小于等于 n 的節點個數 如果子樹個數小于k,那么就在同一層向右平移1, 否則就跳到cur的一下層第一個子節點 點擊查看代碼 class Solution 閱讀全文
摘要:
三種遍歷都是用棧維護二叉樹前序遍歷節點順序 前序遍歷 模擬前序遍歷即可,記錄順序和入棧順序一致 class Solution { public List<Integer> preorderTraversal(TreeNode root) { List<Integer> ans = new Array 閱讀全文
摘要:
215. 數組中的第K個最大元素 權值樹狀數組+二分 class Solution { int[] c; int up; public int findKthLargest(int[] nums, int k) { // 離散化 // 去重+排序 Set<Integer> set = new Tre 閱讀全文