Next Greater Element III Given a positive 32-bit integer n, you need to find the smallest 32-bit integer which has exactly the same digits existing in the integer nand is greater in value than n. If no such positive 32-bit integer exists, you need to return -1. Example 1: Input: 12...
Given a positive 32-bit integer n, you need to find the smallest 32-bit integer which has exactly the same digits existing in the integer nand is greater in value than n. If no such positive 32-bit integer exists, you need to return -1. Example 1: Input: 12 Output: 21 Example 2:...
LeetCode题目:556. Next Greater Element III Given a positive 32-bit integer n, you need to find the smallest 32-bit integer which has exactly the same digits existing in the integer n and is greater in value than n. If no such positive 32-bit integer exists, you need to return -1. ...
[leetcode] 556. Next Greater Element III Description Given a positive 32-bit integer n, you need to find the smallest 32-bit integer which has exactly the same digits existing in the integer n and is greater in value than n. If no such positive 32-bit integer exists, you need to retu...
这个题和之前的503. Next Greater Element II做法一样的,都是使用一个单调递减栈保存每个数字的下标。 首先,把链表遍历一遍,转化成数组问题。 然后遍历数组,需要维护单调递减栈,每个元素的位置都要往栈里面放,放之前先把栈里面小于该元素的全部弹出。
leetcode556. Next Greater Element III 题目要求 Given a positive32-bitintegern, you need to find the smallest32-bitinteger which has exactly the same digits existing in the integernand is greater in value than n. If no such positive32-bitinteger exists, you need to return -1....
Leetcode 556. Next Greater Element III 2. Solution **解析:**Version 1,先将数字n变为字符数组,要找最小的大于n的数,则应该从右往左开始,依次寻找第i位字符右边的大于当前字符的最小数字,然后互换二者位置,由于新数字的第i位字符大于n中的第i位字符,因此新数字i位之后的字符应该从小到大排列,这样可以...
leetcode556. Next Greater Element III 题目要求 Given a positive32-bitintegern, you need to find the smallest32-bitinteger which has exactly the same digits existing in the integernand is greater in value than n. If no such positive32-bitinteger exists, you need to return -1....
Solution Code: publicclassSolution{publicintnextGreaterElement(int n){char[]number=(n+"").toCharArray();int i,j;// I) Start from the right most digit and// find the first digit that is// smaller than the digit next to it.for(i=number.length-1;i>0;i--){if(number[i-1]<number...
[LeetCode] 556. Next Greater Element III Given a positive integern, findthe smallest integer which has exactly the same digits existing in the integernand is greater in value thann. If no such positive integer exists, return-1. Note that the returned integer should fit in 32-bit integer, ...