leetcode738
Posted AsenYang
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了leetcode738相关的知识,希望对你有一定的参考价值。
public class Solution { public int MonotoneIncreasingDigits(int N) { var num = N.ToString(); var len = num.Length; if (len == 1) { return N; } int[] X = new int[len]; for (int i = 0; i < len; i++) { X[i] = Convert.ToInt32(num[i].ToString()); } var change = true; while (change) { var change_count = 0; for (int i = 1; i < len; i++) { var n1 = X[i - 1]; var n2 = X[i]; if (n1 > n2) { change_count++; X[i - 1] -= 1; for (int j = i; j < len; j++) { X[j] = 9; } change = true; break; } } if (change_count == 0) { change = false; } } var temp = ""; for (int i = 0; i < len; i++) { temp += X[i]; } var result = Convert.ToInt32(temp); return result; } }
以上是关于leetcode738的主要内容,如果未能解决你的问题,请参考以下文章
[LeetCode] 738. Monotone Increasing Digits
*Leetcode 738. Monotone Increasing Digits
Codeforces Round #738 (Div. 2)
leetcode_1292. Maximum Side Length of a Square with Sum Less than or Equal to Threshold_[二维前缀和](代码片段