当前位置:网站首页>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
边栏推荐
- JS quick start (I)
- Téléchargement des données de conception des puces
- The zblog plug-in supports the plug-in pushed by Baidu Sogou 360
- Topic not received? Try this
- [matlab] when matrix multiplication in Simulink user-defined function does not work properly, matrix multiplication module in module library can be used instead
- Recursive construction of maximum binary tree
- Myabtis_Plus
- 有 Docker 谁还在自己本地安装 Mysql ?
- Chip design data download
- padavan手动安装php
猜你喜欢
JS复制图片到剪切板 读取剪切板
Main window in QT learning 27 application
Quick analysis of Intranet penetration helps the foreign trade management industry cope with a variety of challenges
Excel import function of jeesite form page
2022 National latest fire-fighting facility operator (primary fire-fighting facility operator) simulation questions and answers
Linux server development, MySQL transaction principle analysis
Explore dry goods! Apifox construction ideas
Fast parsing intranet penetration escorts the document encryption industry
Introduction to basic components of wechat applet
Thinkcmf6.0安装教程
随机推荐
Excel import function of jeesite form page
数据库实时同步利器——CDC(变化数据捕获技术)
Qt学习26 布局管理综合实例
Few shot Learning & meta learning: small sample learning principle and Siamese network structure (I)
Myabtis_Plus
CDC (change data capture technology), a powerful tool for real-time database synchronization
央视太暖心了,手把手教你写HR最喜欢的简历
贝叶斯定律
运放电路的反馈电阻上并联一个电容是什么作用
Chip design data download
【数字IC验证快速入门】17、SystemVerilog学习之基本语法4(随机化Randomization)
积分商城管理系统中应包含的四大项
LeetCode简单题之字符串中最大的 3 位相同数字
Dedecms collects content without writing rules
ROS bridge notes (05) - Carla_ ackermann_ Control function package (convert Ackermann messages into carlaegovehiclecontrol messages)
Blob 对象介绍
ZCMU--1492: Problem D(C语言)
[Matlab] Simulink 自定义函数中的矩阵乘法工作不正常时可以使用模块库中的矩阵乘法模块代替
快解析内网穿透为文档加密行业保驾护航
Visualization Document Feb 12 16:42