Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd3adb6a

Browse files
committed
add 98, modify 100
1 parentaec1b03 commitd3adb6a

File tree

3 files changed

+31
-11
lines changed

3 files changed

+31
-11
lines changed

‎Easy/100-sameTree.js‎

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,10 @@
1010
*@param {TreeNode} q
1111
*@return {boolean}
1212
*/
13-
varisSameTree=function(p,q){
14-
if(p===null&&q===null)returntrue;
15-
if(p!==null&&q!==null&&p.val===q.val){
16-
if(isSameTree(p.left,q.left)&&isSameTree(p.right,q.right)){
17-
returntrue;
18-
}
19-
}
20-
21-
returnfalse;
22-
};
13+
varisSameTree=function(p,q){
14+
if(!p&&!q)returntrue;
15+
if(p&&q&&p.val===q.val){
16+
if(isSameTree(p.left,q.left)&&isSameTree(p.right,q.right))returntrue;
17+
}
18+
returnfalse;
19+
};

‎Medium/98-validateBST.js‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* Definition for a binary tree node.
3+
* function TreeNode(val) {
4+
* this.val = val;
5+
* this.left = this.right = null;
6+
* }
7+
*/
8+
/**
9+
*@param {TreeNode} root
10+
*@return {boolean}
11+
*/
12+
varisValidBST=function(root){
13+
varMIN=-(Math.pow(2,53)-1);
14+
varMAX=Math.pow(2,53)-1;
15+
returnhelper(root,MIN,MAX);
16+
};
17+
18+
varhelper=function(root,min,max){
19+
if(!root)returntrue;
20+
if(root.val<=min||root.val>=max)returnfalse;
21+
returnhelper(root.left,min,root.val)&&helper(root.right,root.val,max);
22+
};

‎README.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,10 @@
109109
*[89. Gray Code](https://leetcode.com/problems/gray-code/) -[Solution](./Medium/89-grayCode.js)
110110
*[90. Subsets II](https://leetcode.com/problems/subsets-ii/) -[Solution](./Medium/90-subsetsII.js)
111111
*[92. Reverse Linked List II](https://leetcode.com/problems/reverse-linked-list-ii/) -[Solution](./Medium/92-reverseLinkedListII.js)
112-
*[93. Restore IP Addresses](https://leetcode.com/problems/restore-ip-addresses/) -[Solution](./Medium/93-restoreIPAddresses.js)
112+
*[93. Restore IP Addresses](https://leetcode.com/problems/restore-ip-addresses/) -[Solution](./Medium/93-restoreIPAddresses.js)
113113
*[94. Binary Tree Inorder Traversal](https://leetcode.com/problems/binary-tree-inorder-traversal/) -[Solution](./Medium/94-binaryTreeInorder.js)
114114
*[96. Unique Binary Search Trees](https://leetcode.com/problems/unique-binary-search-trees/) -[Solution](./Medium/96-uniqueBinarySearchTrees.js)
115+
*[98. Validate Binary Search Tree](https://leetcode.com/problems/validate-binary-search-tree/) -[Solution](./Medium/98-validateBST.js)
115116
*[108. Convert Sorted Array to Binary Search Tree](https://leetcode.com/problems/convert-sorted-array-to-binary-search-tree/) -[Solution](./Medium/108-convertSortedArraytoBST.js)
116117
*[116. Populating Next Right Pointers in Each Node](https://leetcode.com/problems/populating-next-right-pointers-in-each-node/) -[Solution](./Medium/116-PopulatingNextRightPointersinEachNode.js)
117118
*[121. Best Time to Buy and Sell Stock](https://leetcode.com/problems/best-time-to-buy-and-sell-stock/) -[Solution](./Medium/121-bestTimeToBuySellStock.js)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp