Skip to content

Commit 313f66f

Browse files
add 988
1 parent 3b26799 commit 313f66f

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

Diff for: README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -315,4 +315,5 @@ LeetCode
315315
|0982|[Triples with Bitwise AND Equal To Zero](https://leetcode.com/problems/triples-with-bitwise-and-equal-to-zero/) | c | [c++](./src/0982-Triples-with-Bitwise-AND-Equal-To-Zero/0982.cpp) |[python](./src/0982-Triples-with-Bitwise-AND-Equal-To-Zero/0982.py)|||Hard|
316316
|0983|[Minimum Cost For Tickets](https://leetcode.com/problems/minimum-cost-for-tickets/) | c | [c++](./src/0983-Minimum-Cost-For-Tickets/0983.cpp) |[python](./src/0983-Minimum-Cost-For-Tickets/0983.py)|||Medium|
317317
|0984|[String Without AAA or BBB](https://leetcode.com/problems/string-without-aaa-or-bbb/) | c | [c++](./src/0984-String-Without-AAA-or-BBB/0984.cpp) |[python](./src/0984-String-Without-AAA-or-BBB/0984.py)|||Easy|
318-
|0985|[Sum of Even Numbers After Queries](https://leetcode.com/problems/sum-of-even-numbers-after-queries/) | c | [c++](./src/0985-Sum-of-Even-Numbers-After-Queries/0985.cpp) |[python](./src/0985-Sum-of-Even-Numbers-After-Queries/0985.py)|||Easy|
318+
|0985|[Sum of Even Numbers After Queries](https://leetcode.com/problems/sum-of-even-numbers-after-queries/) | c | [c++](./src/0985-Sum-of-Even-Numbers-After-Queries/0985.cpp) |[python](./src/0985-Sum-of-Even-Numbers-After-Queries/0985.py)|||Easy|
319+
|0988|[Smallest String Starting From Leaf](https://leetcode.com/problems/smallest-string-starting-from-leaf/) | c | [c++](./src/0988-Smallest-String-Starting-From-Leaf/0988.cpp) |[python](./src/0988-Smallest-String-Starting-From-Leaf/0988.py)|||Easy|

Diff for: src/0988-Smallest-String-Starting-From-Leaf/0988.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include <string>
2+
#include <vector>
3+
using namespace std;
4+
5+
static int x = []() {std::ios::sync_with_stdio(false); cin.tie(0); return 0; }();
6+
class Solution
7+
{
8+
public:
9+
string smallestFromLeaf(TreeNode* r)
10+
{
11+
if (r == nullptr) return "|";
12+
auto s = string(1, 'a' + r->val);
13+
return r->left == r->right ? s : min(smallestFromLeaf(r->left) + s, smallestFromLeaf(r->right) + s);
14+
}
15+
};

Diff for: src/0988-Smallest-String-Starting-From-Leaf/0988.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Definition for a binary tree node.
2+
class TreeNode:
3+
def __init__(self, x):
4+
self.val = x
5+
self.left = None
6+
self.right = None
7+
8+
class Solution:
9+
def smallestFromLeaf(self, root: 'TreeNode',path="") -> 'str':
10+
if not root:
11+
return "~"
12+
s = chr(root.val + 97)
13+
return s if root.left == root.right else min(self.smallestFromLeaf(root.left)\
14+
+ s, self.smallestFromLeaf(root.right) + s)

0 commit comments

Comments
 (0)