-
738.单调递增的数字
-
class Solution { public:int monotoneIncreasingDigits(int n) {string a = to_string(n);int k = 0;for (int i = a.size() - 1; i > 0; i--) {if (a[i] < a[i - 1]) {k = i;a[i-1]--;}}cout << k << endl;if (k != 0){for (int i = a.size() - 1; i >= k; i--) {a[i] = '9';}}return stoi(a); } } ;
-
968.监控二叉树
-
class Solution { public:int ans = 0;// 0是未被覆盖,1是摄像头位,2是被覆盖int dfs(TreeNode* node) {if (node==NULL)return 2;int left = dfs(node->left);int right = dfs(node->right);if (left == 0 || right == 0) {ans++;return 1;}if (left == 1 || right == 1) {return 2;}return 0;}int minCameraCover(TreeNode* root) {if (dfs(root) == 0)ans++;return ans;} };