随笔分类 - Leetcode
摘要:98. Validate Binary Search Tree class Solution { public: bool isValidBST(TreeNode* root) { return dfs(root,NULL,NULL); } // 此处要最大最小是因为BST需要比较的是全局的最大最小
阅读全文
摘要:5. Longest Palindromic Substring: 最长回文子串 1) 中心扩散法: 分成奇偶由中间向两边拓展,取最长的 class Solution: def longestPalindrome(self, s: str) -> str: res = "" maxLen = 0 n
阅读全文
摘要:反转链表 -迭代 class Solution { public ListNode reverseList(ListNode head) { ListNode prev = null; ListNode curr = head; while (curr != null) { ListNode tmp
阅读全文
摘要:子集 class Solution { public: vector<vector<int>> res; vector<vector<int>> subsets(vector<int>& nums) { vector<int> sub; backtrack(nums,0,sub); return r
阅读全文
摘要:99%的二分搜索问题都属于这3个模板中的1个。 时间复杂度:O(log n) 空间复杂度:O(1)
阅读全文
摘要:class Solution { public: int findMin(vector<int>& nums) { int l = 0, r = nums.size()-1; int n = nums.size(); while(l<r){ int mid = (l+r)/2; int val =
阅读全文
摘要:1 class Solution { 2 public: 3 int search(vector<int>& nums, int target) { 4 int l = 0, r = nums.size()-1; 5 while(l<=r){ 6 int mid = l + (r-l)/2; 7 i
阅读全文
浙公网安备 33010602011771号