Open yankewei opened 3 years ago
遍历一遍即可 func secondHighest(s string) int { ret := [2]int{-1,-1} for i := 0; i < len(s); i++ { diff := int(s[i] - '0') if diff <= 9 { if diff > ret[0] { ret[1] = ret[0] ret[0] = diff } else if diff > ret[1] && diff != ret[0]{ ret[1] = diff } } } return ret[1] }
给你一个混合字符串 s ,请你返回 s 中 第二大 的数字,如果不存在第二大的数字,请你返回 -1 。
混合字符串 由小写英文字母和数字组成。
示例 1:
示例 2:
提示: