Skip to content

Commit c0be1da

Browse files
committed
contest
1 parent 1aa4ac3 commit c0be1da

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed

Diff for: 513. Find Bottom Left Tree Value.cpp

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* Definition for a binary tree node.
3+
* struct TreeNode {
4+
* int val;
5+
* TreeNode *left;
6+
* TreeNode *right;
7+
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
8+
* };
9+
*/
10+
class Solution {
11+
12+
void helper(TreeNode *root, pair<int,int> &value, int level) {
13+
14+
if (!root)
15+
return;
16+
17+
if (level > value.first) {
18+
value.first = level;
19+
value.second = root->val;
20+
}
21+
22+
helper(root->left, value, level+1);
23+
helper(root->right, value, level+1);
24+
25+
}
26+
27+
28+
public:
29+
int findBottomLeftValue(TreeNode* root) {
30+
31+
pair<int, int> value = make_pair(-1,-1); // level, value
32+
33+
helper(root, value, 0);
34+
return value.second;
35+
36+
}
37+
};

Diff for: 520. Detect Capital.cpp

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
class Solution {
2+
public:
3+
bool detectCapitalUse(string word) {
4+
5+
bool small = false;
6+
bool big = false;
7+
8+
if (word.size() <= 1)
9+
return true;
10+
11+
if (islower(word[0]))
12+
small = true;
13+
14+
else if (isupper(word[0])) {
15+
big = true;
16+
17+
if (islower(word[1])) {
18+
big = false;
19+
small = true;
20+
}
21+
}
22+
23+
for(int i = 1;i<word.length(); ++i) {
24+
25+
if (small && islower(word[i]))
26+
continue;
27+
28+
else if(big && isupper(word[i]))
29+
continue;
30+
31+
else
32+
return false;
33+
34+
}
35+
36+
return true;
37+
38+
}
39+
};

0 commit comments

Comments
 (0)