当前位置:网站首页>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
边栏推荐
- 力扣(LeetCode)187. 重复的DNA序列(2022.07.06)
- 【數字IC驗證快速入門】15、SystemVerilog學習之基本語法2(操作符、類型轉換、循環、Task/Function...內含實踐練習)
- Few shot Learning & meta learning: small sample learning principle and Siamese network structure (I)
- The principle and implementation of buffer playback of large video files
- 互动送书-《Oracle DBA工作笔记》签名版
- ZCMU--1492: Problem D(C语言)
- Ansible
- Blob 對象介紹
- 复杂网络建模(三)
- Thinkcmf6.0安装教程
猜你喜欢
Dedecms collects content without writing rules
Introduction to basic components of wechat applet
Thinkcmf6.0安装教程
Network learning (III) -- highly concurrent socket programming (epoll)
QT learning 28 toolbar in the main window
调用 pytorch API完成线性回归
有 Docker 谁还在自己本地安装 Mysql ?
These five fishing artifacts are too hot! Programmer: I know, delete it quickly!
王爽 《汇编语言》之寄存器
LeetCode中等题之我的日程安排表 I
随机推荐
Chip design data download
Explore dry goods! Apifox construction ideas
OpenJudge NOI 2.1 1752:鸡兔同笼
JS cross browser parsing XML application
Binary tree and heap building in C language
Es FAQ summary
JSON data flattening pd json_ normalize
Cnopendata geographical distribution data of religious places in China
Summary of redis functions
Uniapp mobile terminal forced update function
Visualization Document Feb 12 16:42
Network learning (I) -- basic model learning
探索干货篇!Apifox 建设思路
【数字IC验证快速入门】15、SystemVerilog学习之基本语法2(操作符、类型转换、循环、Task/Function...内含实践练习)
Blob object introduction
Complex network modeling (I)
Thinkcmf6.0安装教程
These five fishing artifacts are too hot! Programmer: I know, delete it quickly!
It took "7" years to build the robot framework into a micro service
【数字IC验证快速入门】10、Verilog RTL设计必会的FIFO