当前位置:网站首页>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边栏推荐
- (resolved) difference between leftmost prefix and overlay index
- Summary ranges of leetcode topic resolution
- 986. Interval List Intersections
- 复选框的基本使用与实现全选和反选功能
- Basic use of check boxes and implementation of select all and invert selection functions
- 7-调色板-CALayer和触摸
- C # advanced learning -- virtual method
- Deep analysis and Simulation of vector
- 实战监听Eureka client的缓存更新
- 给你的win10装一个wget
猜你喜欢

jmeter压测结果分析

Self organizing map neural network (SOM)

Keng dad's "dedication blessing": red packet technology explosion in Alipay Spring Festival Gala

鸿蒙读取资源文件

PCB电路板特性检查项目都有哪些?

Summary of communication mode and detailed explanation of I2C drive

复选框的基本使用与实现全选和反选功能

最常用的5中流ETL模式

Vulnhub | DC: 4 |【實戰】

Data assets are king, analyzing the relationship between enterprise digital transformation and data asset management
随机推荐
Implementing an open source app store with swiftui
给你的win10装一个wget
Cloud computing "half peak"
Open source stealing malware mercurial found in the field for "educational purposes"
5、 Project management
usb peripheral 驱动 - configfs
Third party payment in the second half: scuffle to symbiosis
3-progressbar and secondary cropping
USB peripheral driver - configfs
Chapter 1 open LDAP master-slave synchronization tower construction
史上最污技术解读,60 个 IT 术语我居然秒懂了......
After easynvr video is enabled, no video file is generated. How to solve this problem?
Code quality level 3 - readable code
3. Caller 服务调用 - dapr
[operating steps] how to set the easynvr hardware device to be powered on without automatic startup?
Integers and operators in go data types (3)
Quickly create a consumer cluster
训练后的随机森林模型导出和加载
Optimize your gradle module with a clean architecture
开源技术交流丨批流一体数据同步引擎ChunJun数据还原-DDL功能模块解析