class Solution {
public:
int monotoneIncreasingDigits(int N) {
string strNum = to_string(N);
int flag = strNum.size();
for (int i = strNum.size() - 1; i > 0; i--)
{
if (strNum[i - 1] > strNum[i] ) {
flag = i;
strNum[i - 1]--;
}
}
for (int i = flag; i < strNum.size(); i++) {
strNum[i] = '9';
}
return stoi(strNum);
}
};
968监控二叉树
class Solution {
private:
int result;
int traversal(TreeNode* cur)
{
if (cur == NULL) return 2;
int left = traversal(cur->left);
int right = traversal(cur->right);
if (left == 2 && right == 2) return 0;
else if (left == 0 || right == 0)
{
result++;
return 1;
}
else return 2;
}
public:
int minCameraCover(TreeNode* root) {
result = 0;
if (traversal(root) == 0)
{
result++;
}
return result;
}
};