1614
沙比提~
数括号就行了,( 加1 ,)减 1 ,返回 数字的最大值
class Solution {
public int maxDepth(String s) {
// int count=0;
// int max=0;
// for(int i=0;i<s.length();i++){
// if(s.charAt(i)=='('){
// count++;
// max=Math.max(count,max);
// }else if(s.charAt(i)==')'){
// count--;
// }
// }
// return max;
Deque<Character> stack = new LinkedList();
int max=0;
for(int i=0;i<s.length();i++){
if(s.charAt(i)=='('){
stack.push('(');
max=Math.max(max,stack.size());
}else if(s.charAt(i)==')'){
stack.pop();
}
}
return max;
}
}
701
代码
class Solution {
public TreeNode insertIntoBST(TreeNode root, int val) {
if(root==null){
return new TreeNode(val);
}
if(root.val>val){
root.left=insertIntoBST(root.left,val);
}
if(root.val<val){
root.right =insertIntoBST(root.right ,val);
}
return root;
}
}