当前位置:网站首页>The largest 3 same digits in the string of leetcode simple question
The largest 3 same digits in the string of leetcode simple question
2022-07-07 08:09:00 【·Starry Sea】
subject
Give you a string num , Represents a large integer . If an integer satisfies all of the following conditions , The integer is considered to be a High quality integer :
The integer is num One length of the is 3 Of Substring .
The integer is repeated by a unique number 3 Secondary composition .
Returns... As a string The largest good integer . If there is no integer that meets the requirements , Then return an empty string “” .
Be careful :
Substring Is a sequence of consecutive characters in a string .
num Or high-quality integers may exist Leading zero .
Example 1:
Input :num = “6777133339”
Output :“777”
explain :num There are two high-quality integers in :“777” and “333” .
“777” It's the biggest one , So back “777” .
Example 2:
Input :num = “2300019”
Output :“000”
explain :“000” Is the only good integer .
Example 3:
Input :num = “42352338”
Output :“”
explain : There is no length of 3 An integer consisting of only one unique number . therefore , There are no good integers .
Tips :
3 <= num.length <= 1000
num Just numbers (0 - 9) form
source : Power button (LeetCode)
Their thinking
This problem only needs to be done with a length of 3 And then traverse the entire string , Find the largest number that meets the conditions .
class Solution:
def largestGoodInteger(self, num: str) -> str:
MIN=''
for i in range(0,len(num)-2):
if num[i]==num[i+1] and num[i+1]==num[i+2]:
if MIN=='':
MIN=num[i]*3
else:
MIN=num[i]*3 if int(num[i]*3)>int(MIN) else MIN
return MIN

边栏推荐
- Complex network modeling (III)
- Example of file segmentation
- Few shot Learning & meta learning: small sample learning principle and Siamese network structure (I)
- 有 Docker 谁还在自己本地安装 Mysql ?
- Introduction to basic components of wechat applet
- 海信电视开启开发者模式
- 【数字IC验证快速入门】14、SystemVerilog学习之基本语法1(数组、队列、结构体、枚举、字符串...内含实践练习)
- padavan手动安装php
- It took "7" years to build the robot framework into a micro service
- Cnopendata geographical distribution data of religious places in China
猜你喜欢

Network learning (III) -- highly concurrent socket programming (epoll)

Custom class loader loads network class

快速使用 Jacoco 代码覆盖率统计

JS cross browser parsing XML application

Network learning (II) -- Introduction to socket

【数字IC验证快速入门】15、SystemVerilog学习之基本语法2(操作符、类型转换、循环、Task/Function...内含实践练习)

Es FAQ summary

JS复制图片到剪切板 读取剪切板

船载雷达天线滑环的使用

Network learning (I) -- basic model learning
随机推荐
Complex network modeling (III)
Padavan manually installs PHP
海信电视开启开发者模式
力扣(LeetCode)187. 重复的DNA序列(2022.07.06)
青龙面板--整理能用脚本
Minimum absolute difference of binary search tree (use medium order traversal as an ordered array)
json 数据展平pd.json_normalize
Notes on PHP penetration test topics
C language queue
Blob 對象介紹
Lattice coloring - matrix fast power optimized shape pressure DP
Myabtis_Plus
Linux server development, SQL statements, indexes, views, stored procedures, triggers
Linux Installation MySQL 8.0 configuration
Visualization Document Feb 12 16:42
贝叶斯定律
C language flight booking system
Search for an element in a binary search tree (BST)
面试题(CAS)
Thinkcmf6.0 installation tutorial