java.lang.Object
g1701_1800.s1796_second_largest_digit_in_a_string.Solution

public class Solution extends java.lang.Object
1796 - Second Largest Digit in a String.

Easy

Given an alphanumeric string s, return the second largest numerical digit that appears in s, or -1 if it does not exist.

An alphanumeric string is a string consisting of lowercase English letters and digits.

Example 1:

Input: s = “dfa12321afd”

Output: 2

Explanation: The digits that appear in s are [1, 2, 3]. The second largest digit is 2.

Example 2:

Input: s = “abc1111”

Output: -1

Explanation: The digits that appear in s are [1]. There is no second largest digit.

Constraints:

  • 1 <= s.length <= 500
  • s consists of only lowercase English letters and/or digits.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    secondHighest(java.lang.String s)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • secondHighest

      public int secondHighest(java.lang.String s)