当前位置:网站首页>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

边栏推荐
- 【数字IC验证快速入门】14、SystemVerilog学习之基本语法1(数组、队列、结构体、枚举、字符串...内含实践练习)
- LeetCode简单题之找到一个数字的 K 美丽值
- Qt学习27 应用程序中的主窗口
- game攻防世界逆向
- Open source ecosystem | create a vibrant open source community and jointly build a new open source ecosystem!
- Blob object introduction
- Explore dry goods! Apifox construction ideas
- QT learning 26 integrated example of layout management
- 【数字IC验证快速入门】17、SystemVerilog学习之基本语法4(随机化Randomization)
- Codeforce c.strange test and acwing
猜你喜欢

Linux server development, MySQL transaction principle analysis

Dedecms collects content without writing rules

互动送书-《Oracle DBA工作笔记》签名版

【数字IC验证快速入门】10、Verilog RTL设计必会的FIFO

LeetCode简单题之找到一个数字的 K 美丽值

Thinkcmf6.0 installation tutorial

UnityHub破解&Unity破解

微信小程序基本组件使用介绍

game攻防世界逆向

【数字IC验证快速入门】11、Verilog TestBench(VTB)入门
随机推荐
LeetCode简单题之找到一个数字的 K 美丽值
Relevant data of current limiting
芯片 设计资料下载
Es FAQ summary
Topic not received? Try this
Blob 對象介紹
C语言队列
[VHDL parallel statement execution]
Linux server development, MySQL index principle and optimization
Padavan manually installs PHP
探索干货篇!Apifox 建设思路
C language communication travel card background system
The zblog plug-in supports the plug-in pushed by Baidu Sogou 360
[UVM foundation] what is transaction
复杂网络建模(二)
【数字IC验证快速入门】11、Verilog TestBench(VTB)入门
复杂网络建模(一)
复杂网络建模(三)
船载雷达天线滑环的使用
青龙面板-今日头条