class Solution { public boolean checkInclusion(String s1, String s2) { int n=s1.length(), m=s2.length(); if (n>m) return false; int[] cnt = new int[26]; for (int i=0; i<n; i++) cnt[s1.charAt(i)-'a']++; int left=
left(NULL), right(NULL) {} * }; */ class Solution { public: map<int, vector<int>>m; vector<vector<int>> zigzagLevelOrder(TreeNode* root) { vector<vector<int>>res; if(root == NULL) return res; BFS(root, 0); for(auto c : m){ if(c.first%2) //翻转...
3Sum Medium 4Sum Medium Two Sum II - Input Array Is Sorted Medium Two Sum III - Data structure design Easy Subarray Sum Equals K Medium Two Sum IV - Input is a BST Easy Two Sum Less Than K Easy Max Number of K-Sum Pairs Medium Count Good Meals Medium Count Number of Pairs With Abs...
能在O(1)的时间或是最小值如何用一个数组实现两个树:二叉搜索树的最小值二叉树的高度BST的第K大...
1/**2* Definition for a binary tree node.3* public class TreeNode {4* int val;5* TreeNode left;6* TreeNode right;7* TreeNode(int x) { val = x; }8* }9*/10publicclassSolution {11publicbooleanisValidBST(TreeNode root) {12returncheckValid(root, Integer.MIN_VALUE, Integer.MAX_VAL...
1617returnleftVal < node->val && node->val < rightVal && check(node->left, leftVal, node->val) &&18check(node->right, node->val, rightVal);19}2021boolisValidBST(TreeNode *root) {22//Start typing your C/C++ solution below23//DO NOT write int main() function24returncheck(root, ...
root.right=self.sortedArrayToBST(num[mid+1:])returnroot Balanced Binary Tree 题目:Balanced Binary Tree Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every nod...
230 Kth Smallest Element in a BST 34.0% Medium 229 Majority Element II 24.2% Medium 228 Summary Ranges 21.6% Easy 227 Basic Calculator II 22.2% Medium Minimum Height Trees 【题目】For a undirected graph with tree characteristics, we can choose any node as the root. The result graph is then...
449 Serialize and Deserialize BST 41.20% Medium 448 Find All Numbers Disappeared in an Array 58.30% Easy 447 Number of Boomerangs 42.20% Easy 446 Arithmetic Slices II - Subsequence 22.30% Hard 445 Add Two Numbers II 45.40% Medium 444 Sequence Reconstruction $ 20.50% Medium 443 String Compression...
bool: self.nodeValueList = [] if root is None: return True if root.left is None and root.right is None: return True self.inOrder(root) for i in range(len(self.nodeValueList) - 1): if self.nodeValueList[i] >= self.nodeValueList[i + 1]: self.isBST = False return self.isBST ...