当前位置:网站首页>670. Maximum Swap
670. Maximum Swap
2022-06-23 08:24:00 【ujn20161222】
670. Maximum Swap
Medium
2375137Add to ListShare
You are given an integer num. You can swap two digits at most once to get the maximum valued number.
Return the maximum valued number you can get.
Example 1:
Input: num = 2736 Output: 7236 Explanation: Swap the number 2 and the number 7.
Example 2:
Input: num = 9973 Output: 9973 Explanation: No swap.
Constraints:
0 <= num <= 108
Accepted
158,888
Submissions
335,266
class Solution:
def maximumSwap(self, num: int) -> int:
D=list(str(num))
dp=list(accumulate(D[::-1],max))[::-1]
for i,digit in enumerate(D):
if dp[i]>digit:
for k in range(i+1,len(D)):
if D[k]==dp[i]:
j=k
D[i],D[j]=D[j],D[i]
return "".join(D)
return num边栏推荐
- ArcLayoutView: 一个弧形布局的实现
- 6、 Web Architecture Design
- Go language basic conditional statement if
- 开源技术交流丨批流一体数据同步引擎ChunJun数据还原-DDL功能模块解析
- Point cloud library PCL from introduction to mastery Chapter 10
- 驱动架构 & platform平台总线驱动模型
- You have a string of code, but do not support the lower version of go; Judge the go version number, you deserve it!
- How to use the template library of barcode label software
- Set接口和Set子实现类
- jmeter压测结果分析
猜你喜欢
随机推荐
Subsets of leetcode topic resolution
Vulnhub | DC: 4 |【實戰】
史上最污技术解读,60 个 IT 术语我居然秒懂了......
3. Caller 服务调用 - dapr
Map (set) operation in go language
The most commonly used 5-stream ETL mode
走好数据中台最后一公里,为什么说数据服务API是数据中台的标配?
Why do we say that the data service API is the standard configuration of the data midrange?
Vulnhub | dc: 3 | [actual combat]
You have a string of code, but do not support the lower version of go; Judge the go version number, you deserve it!
523. Continuous Subarray Sum
Set interface and set sub implementation classes
Optimize your gradle module with a clean architecture
Deep learning ----- convolution (conv2d) bottom layer
Deep analysis and Simulation of vector
Can portals be the next decentraland?
Go language basic conditional statement if
实战监听Eureka client的缓存更新
There are some limitations in cluster expansion and contraction
Paper reading [quovadis, action recognition? A new model and the dynamics dataset]





![[paper notes] catching both gray and black swans: open set supervised analog detection*](/img/52/787b25a9818cfc6a1897af81d41ab2.png)



