首页 > 其他分享 >2496

2496

时间:2023-07-15 16:34:47浏览次数:30  
标签:数字 包含 strs 值为 2496 字符串 alic3

一个由字母和数字组成的字符串的  定义如下:

  • 如果字符串  包含数字,那么值为该字符串在 10 进制下的所表示的数字。
  • 否则,值为字符串的 长度 

给你一个字符串数组 strs ,每个字符串都只由字母和数字组成,请你返回 strs 中字符串的 最大值 。

 

示例 1:

输入:strs = ["alic3","bob","3","4","00000"]
输出:5
解释:
- "alic3" 包含字母和数字,所以值为长度 5 。
- "bob" 只包含字母,所以值为长度 3 。
- "3" 只包含数字,所以值为 3 。
- "4" 只包含数字,所以值为 4 。
- "00000" 只包含数字,所以值为 0 。
所以最大的值为 5 ,是字符串 "alic3" 的值。
class Solution(object):
    def maximumValue(self, strs):
        """
        :type strs: List[str]
        :rtype: int
        """
        r=0
        for s in strs:
            if s.isdigit():
                r=max(int(s),r)
            else:
                r=max(r,len(s))
        return r

 

标签:数字,包含,strs,值为,2496,字符串,alic3
From: https://www.cnblogs.com/LYoungH/p/17556434.html

相关文章

  • NC24961 Hotel
    题目链接题目题目描述ThecowsarejourneyingnorthtoThunderBayinCanadatogainculturalenrichmentandenjoyavacationonthesunnyshoresofLakeSuperior.Bessie,everthecompetenttravelagent,hasnamedtheBullmooseHotelonfamedCumberlandStr......