* Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */ class Solution { public: bool isValidBST(T
LeetCode 98: Valid Binary Search Tree This answer is so awesome!! /*** Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * }*/classSolution { Integer min=null;publicbooleanisValidBST(Tre...
0235-lowest-common-ancestor-of-a-binary-search-tree.scala 0242-valid-anagram.scala 0322-coin-change.scala 0347-top-k-frequent-elements.scala 0394-decode-string.scala 0435-non-overlapping-intervals.scala 0485-max-consecutive-ones.scala 0509-fibonacci-number.scala 0572-subtree-of-another-tree.scala ...
package leetcode // 解法一 栈 func longestValidParentheses(s string) int { stack, res := []int{}, 0 stack = append(stack, -1) for i := 0; i < len(s); i++ { if s[i] == '(' { stack = append(stack, i) } else { stack = stack[:len(stack)-1] if len(stack) ==...
My Solutions to Leetcode problems. All solutions support C++ language, some support Java and Python. Multiple solutions will be given by most problems. Enjoy:) 我的Leetcode解答。所有的问题都支持C++语言,一部分问题支持Java语言。近乎所有问题都会提供多个算
Leetcode May Challenge - 05/14: Implement Trie (Prefix Tree)(Python) 题目描述 Implement a trie with insert, search, and startsWith methods. Note: You may assume that all inputs are consist of lowercase letters a-z. All inputs are guaranteed to be non-empty strings. 例子 Trie......
LeetCode:Longest Valid Parentheses Given a string containing just the characters'('and')', find the length of the longest valid (well-formed) parentheses substring.For"(()", the longest valid parentheses substring is"()", which has length = 2....
packageleetcode// 解法一funcisAnagram(sstring,tstring)bool{alphabet:=make([]int,26)sBytes:=[]byte(s)tBytes:=[]byte(t)iflen(sBytes)!=len(tBytes){returnfalse}fori:=0;i<len(sBytes);i++{alphabet[sBytes[i]-'a']++}fori:=0;i<len(tBytes);i++{alphabet[tBytes[i]-'a']--}fo...
921. Minimum Add to Make Parentheses Valid # 题目 # Given a string S of ‘(’ and ‘)’ parentheses, we add the minimum number of parentheses ( ‘(’ or ‘)’, and in any positions ) so that the resulting parentheses string is valid. Formally, a parent
Inorder traversal the tree and compare one by one. 1 /** 2 * Definition for binary tree 3 * struct TreeNode { 4 * int val; 5 * TreeNode *l...