556.Next-Greater-Element-III

556. Next Greater Element III

题目地址

https://leetcode.com/problems/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.

Example 1:
Input: 12
Output: 21

Example 2:
Input: 21
Output: -1

代码

Approach #1 Liner Solution

Approach 2: Brute Force (Time Limit Exceeded)

Last updated

Was this helpful?