Skip to content

Commit c68727b

Browse files
committed
updated 700, note in 3162
1 parent de30904 commit c68727b

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed
Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/*
22
700. Search in a Binary Search Tree
33
4-
Submitted: November 25, 2024
4+
Submitted: December 7, 2024
55
66
Runtime: 0 ms (beats 100.00%)
7-
Memory: 33.56 MB (beats 59.28%)
7+
Memory: 35.52 MB (beats 8.78%)
88
*/
99

1010
/**
@@ -20,15 +20,12 @@ Memory: 33.56 MB (beats 59.28%)
2020
*/
2121
class Solution {
2222
public:
23-
TreeNode* searchBST(TreeNode*& root, const int& val) {
24-
if (root == nullptr) return nullptr;
25-
if (root->val == val) return root;
26-
TreeNode *left = searchBST(root->left, val);
27-
TreeNode *right = searchBST(root->right, val);
28-
if (left != nullptr && left->val == val) return left;
29-
else if (right != nullptr && right->val == val) return right;
30-
else {
31-
return root->val == val ? root : nullptr;
23+
TreeNode* searchBST(TreeNode* root, const int val) {
24+
while (true) {
25+
if (root == nullptr) return nullptr;
26+
if (root->val == val) return root;
27+
if (root->val > val) root = root->left;
28+
else if (root->val < val) root = root->right;
3229
}
3330
}
34-
};
31+
};

3162-find-the-number-of-good-pairs-i.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@
99

1010
class Solution:
1111
def numberOfPairs(self, nums1: List[int], nums2: List[int], k: int) -> int:
12+
# in the inner generator sum is used to count how many elements a condition is true for
1213
return sum(sum((nums1[i] % (nums2[j] * k) == 0) for j in range(len(nums2))) for i in range(len(nums1)))

0 commit comments

Comments
 (0)