查找数组中第二大的数字

Posted

技术标签:

【中文标题】查找数组中第二大的数字【英文标题】:Finding the second highest number in array 【发布时间】:2011-02-06 15:02:19 【问题描述】:

我很难理解在数组中查找第二大数字的方法背后的逻辑。使用的方法是在数组中找到最高但小于之前的最高(已经找到)。我仍然无法弄清楚为什么|| highest_score == second_highest 是必要的。例如我输入了三个数字:98、56、3。没有它,最高和第二高的都是98。请解释一下。

int second highest = score[0];  
if (score[i] > second_highest && score[i] < highest_score || highest_score == second_highest)   
    second_highest = score[i];

【问题讨论】:

你的代码 sn-p 没有说明highest_score是如何初始化的 应该second highestsecond_highest 吗?有循环吗? 非常相似的线程:***.com/questions/1811846/… 和 ***.com/questions/1412751/… 【参考方案1】:

想法是取两个变量 firstmax fm 和 secondmax sm 并遍历数组。

def print2largest(self,A,N): 
        #code here
    if all(A[x]==A[x-1] for x in range(1,N)): 
        return -1
    sm=0
    fs=0
    for i in range(N):
        if A[i]>fs: 
            sm=fs
            fs=A[i]
        elif A[i]>sm and A[i]!=fs: 
            sm=A[i]
    return sm
    
    

【讨论】:

【参考方案2】:
let array = [0,12,74,26,82,176,189,8,55,3,189]; 
let highest=0 ;
let secondHighest = 0;
for (let i = 0; i < array.length; i++)  
if (array[i] > highest)  
    // ...shift the current highest number to second highest
    secondHighest = highest; 
    // ...and set the new highest.
    highest = array[i]; 
 else if (highest > array[i] > secondHighest)  
   // Just replace the second highest
   secondHighest = array[i]; 
  

console.log(secondHighest);

【讨论】:

请尽量避免只是将代码作为答案转储,并尝试解释它的作用和原因。对于没有相关编码经验的人来说,您的代码可能并不明显。【参考方案3】:
 private static void returnSecondHighetsNumber(int[] a) 
         int firstHighest=0;
         int secondHighest=0;
         if(a[0]>=a[1]) 
             firstHighest=a[0];
             secondHighest=a[1];
         else 
             firstHighest=a[1];
             secondHighest=a[0];
         
         for (int i = 2; i < a.length; i++) 
             if(a[i] >=firstHighest) 
                 secondHighest=firstHighest;
                 firstHighest=a[i];
             
             else if(a[i]>=secondHighest) 
                 secondHighest=a[i];
             
         
         System.out.println(firstHighest+"---"+secondHighest);
    

【讨论】:

【参考方案4】:

这个 java 程序帮助在任何给定的数组中找到第二大的数字。 首先,我们必须获得最高价值,然后我们必须获得第二名。

class Demo
    public static void main(String args[])
        int arr[]=321,321,321,43,65,234,56,-1,4,45,-67;
        int max=arr[0];
        int len=arr.length;
        for(int i=0;i<len;i++)
            if(max<arr[i])
                max=arr[i];
            
        

        System.out.println("Max value is "+max);

        int secMax=arr[0];
        for(int j=0;j<len;j++)
            if(max>arr[j])
                if(secMax<arr[j])
                    secMax=arr[j];
                
                else if(secMax>arr[j])
                    secMax=arr[j];
                

            
            else if(max==arr[j])
                //
            

        
                System.out.println("Sec Max value is "+secMax);

    

【讨论】:

虽然此代码可能会解决问题,including an explanation 关于如何以及为什么解决问题将真正有助于提高您的帖子质量,并可能导致更多的赞成票。请记住,您正在为将来的读者回答问题,而不仅仅是现在提问的人。请edit您的回答添加解释并说明适用的限制和假设。【参考方案5】:

数组中的第二大元素: 在 Java 中:

class test2
    public static void main(String[] args) 

int a[] = 1,2,3,9,5,7,6,4,8;
Arrays.sort(a);
int aa = a[a.length -2 ];
System.out.println(aa);


    //main

//end

在 Python 中:

a = [1, 2, 3, 9, 5, 7, 6, 4, 8]

aa = sorted(list(a))
print(aa)
aaa = aa[-2]
print(aaa)

【讨论】:

【参考方案6】:

最简单的方法是——

public class SecondLargest 
    public static void main(String[] args) 
        int[] arr =  1, 2, 5, 6, 3 ;

        int first = Integer.MIN_VALUE;
        int second = Integer.MIN_VALUE;
        for (int i = 0; i < arr.length; i++) 
            // If current element is smaller than first then update both first
            // and second
            if (arr[i] > first) 
                second = first;
                first = arr[i];
            
            // If arr[i] is in between first and second then update second
            else if (arr[i] > second && arr[i] != first) 
                second = arr[i];
            
        
    

【讨论】:

【参考方案7】:

我的想法是你假设数组的第一个和第二个成员是你的第一个最大值和第二个最大值。然后,您获取数组的每个新成员并将其与第二个最大值进行比较。不要忘记将第二个最大值与第一个最大值进行比较。如果它更大,只需交换它们。

   public static int getMax22(int[] arr)
    int max1 = arr[0];
    int max2 = arr[1];
    for (int i = 2; i < arr.length; i++)
        if (arr[i] > max2)
        
            max2 = arr[i];
        

        if (max2 > max1)
        
            int temp = max1;
            max1 = max2;
            max2 = temp;
        
    
     return max2;

【讨论】:

【参考方案8】:

导入 java.util.Scanner;

公共类 SecondHighestFromArrayTest

public static void main(String[] args) 
    Scanner scan = new Scanner(System.in);
    System.out.println("Enter size of Array");
    int size = scan.nextInt();
    int[] arr = new int[size];
    for (int i = 0; i < size; i++) 
        arr[i] = scan.nextInt();
    
    System.out.println("second highest element " + getSecondHighest(arr));


public static int getSecondHighest(int arr[]) 
    int firstHighest = arr[0];
    int secondHighest = arr[0];
    for (int i = 0; i < arr.length; i++) 
        if (arr[i] > firstHighest) 
            secondHighest = firstHighest;
            firstHighest = arr[i];
         else if (arr[i] > secondHighest) 
            secondHighest = arr[i];
        
    
    return secondHighest;

【讨论】:

【参考方案9】:

我有最简单的逻辑来找到第二大的数字可能是,不是。 逻辑在数组中找到两个数之和,其中具有最高值,然后检查两个简单数中哪个更大............

int ar[]=611,4,556,107,5,55,811;
int sum=ar[0]+ar[1];
int temp=0;
int m=ar[0];
int n=ar[1];
for(int i=0;i<ar.length;i++)
    for(int j=i;j<ar.length;j++)
        if(i!=j)
        temp=ar[i]+ar[j];
        if(temp>sum)
            sum=temp;
            m=ar[i];
            n=ar[j];
        
        temp=0;

    
    

if(m>n)
    System.out.println(n);


else
    System.out.println(m);

【讨论】:

【参考方案10】:
   /* Function to print the second largest elements */
    void print2largest(int arr[], int arr_size)
    
   int i, first, second;

   /* There should be atleast two elements */
   if (arr_size < 2)
   
    printf(" Invalid Input ");
    return;
    

   first = second = INT_MIN;
   for (i = 0; i < arr_size ; i ++)
   
    /* If current element is smaller than first
       then update both first and second */
    if (arr[i] > first)
    
        second = first;
        first = arr[i];
    

    /* If arr[i] is in between first and 
       second then update second  */
    else if (arr[i] > second && arr[i] != first)
        second = arr[i];
   
   if (second == INT_MIN)
    printf("There is no second largest elementn");
    else
    printf("The second largest element is %dn", second);
    

【讨论】:

【参考方案11】:
public class SecondLargestNumber

  public static void main(String[] args)
  
    int[] var=-11,-11,-11,-11,115,-11,-9;
    int largest = 0;
    int secLargest = 0;
    if(var.length == 1)
    
      largest = var[0];
      secLargest = var[0];
    
    else if(var.length > 1)
    
      largest= var[0];
      secLargest = var[1];
      for(int i=1;i<var.length;i++)
      
        if(secLargest!=largest)
        
          if(var[i]>largest)
           
            secLargest = largest;
            largest = var[i];
          
          else if(var[i]>secLargest && var[i] != largest)
          
            secLargest= var[i];
          
        
        else
        
          if(var[i]>largest)
          
           secLargest = largest;
           largest = var[i];
          
          else
          
           secLargest = var[i];
          
       
    
  

    System.out.println("Largest: "+largest+" Second Largest: "+secLargest);
  

【讨论】:

如果您解释一下您的答案可能会有所帮助。 OP的代码有什么问题?这是如何解决的?【参考方案12】:
public void findMax(int a[]) 
    int large = Integer.MIN_VALUE;
    int secondLarge = Integer.MIN_VALUE;
    for (int i = 0; i < a.length; i++) 
        if (large < a[i]) 
            secondLarge = large;
            large = a[i];
         else if (a[i] > secondLarge) 
            if (a[i] != large) 
                secondLarge = a[i];
            
        
    
    System.out.println("Large number " + large + " Second Large  number " + secondLarge);

上面的代码已经用具有重复条目、负值的整数数组进行了测试。一次检索最大数和第二大数。仅当数组仅包含相同数字的多个副本(例如 8,8,8,8)或只有一个数字时,此代码才会失败。

【讨论】:

【参考方案13】:
import java.util.Scanner;

public class SecondLargest 

    public static void main(String[] args) 
        Scanner sc = new Scanner(System.in);
        System.out.print("Enter size of array : ");
        int n = sc.nextInt();
        int ar[] = new int[n];
        for(int i=0;i<n;i++)
        
            System.out.print("Enter value for array : ");
            ar[i] = sc.nextInt();
        
        int m=ar[0],m2=ar[0];
        for(int i=0;i<n;i++)
        
            if(ar[i]>m)
                m=ar[i];
        
        for(int i=0;i<n;i++)
        
            if(ar[i]>m2 && ar[i]<m)
                m2=ar[i];
        
        System.out.println("Second largest : "+m2);
        sc.close();
    

【讨论】:

【参考方案14】:

使用以下功能 `

public static int secHigh(int arr[])
            int firstHigh = 0,secHigh = 0;
            for(int x: arr)
                if(x > firstHigh)
                    secHigh = firstHigh;
                    firstHigh = x;
                else if(x > secHigh)
                    secHigh = x;
                
            
            return secHigh;
        

函数调用

int secondHigh = secHigh(arr);

【讨论】:

【参考方案15】:
public class SecondHighest 

    public static void main(String[] args) 
        // TODO Auto-generated method stub

        /*
         * Find the second largest int item in an unsorted array.
         * This solution assumes we have atleast two elements in the array
         * SOLVED! - Order N. 
         * Other possible solution is to solve with Array.sort and get n-2 element.
         * However, Big(O) time NlgN 
         */

        int[] nums = new int[]1,2,4,3,5,8,55,76,90,34,91;
        int highest,cur, secondHighest = -1;

        int arrayLength = nums.length;
        highest = nums[1] > nums[0] ? nums[1] : nums[0];
        secondHighest = nums[1] < nums[0] ? nums[1] : nums[0];

        if (arrayLength == 2) 
            System.out.println(secondHighest);

         else 

            for (int x = 0; x < nums.length; x++) 

                cur = nums[x];
                int tmp;

                if (cur < highest && cur > secondHighest)
                    secondHighest = cur;

                else if (cur > secondHighest && cur > highest) 
                    tmp = highest;
                    highest = cur;
                    secondHighest = tmp;
                

               

            System.out.println(secondHighest);

           
    

【讨论】:

【参考方案16】:
public static void main(String[] args) 

    int[] arr = 0,12,74,56,2,63,45;
    int f1 = 1, f2 = 0, temp = 0;
    int num = 0;

    for (int i = 0; i < arr.length; i++)
        num = arr[i];
        if (f1 < num) 
            temp = f1;
            f1 = num;
            num = temp;
        
        if (f2 < num) 
            temp = f2;
            f2 = num;
            num = temp;
        
    
    System.out.println("First Highest " + f1 + " Second Highest " + f2 + " Third " + num);


【讨论】:

【参考方案17】:
int arr[] = 25, 5, 35, 26, 6, 270, 0;

int large1 = arr[0];
int large2 = arr[1];

for (int i = 2; i < arr.length; i++) 

    if (arr[i] > large1) 

        if (large1 > large2)
            large2 = large1;
        large1 = arr[i];

     else if (arr[i] > large2)
        large2 = arr[i];                    


System.out.println("Large1 " + large1);
System.out.println("Large2 " + large2);

【讨论】:

与其只发布一些代码,即使它回答了问题,请不要犹豫,清楚地评论它的作用/它是如何工作的。谢谢【参考方案18】:

求第二大数:

public class SecondMaxNumbers 

    public void printTwoMaxNumbers(int[] nums)
        int maxOne = 0;
        int maxTwo = 0;
        for(int n:nums)
            if(maxOne < n)
                maxTwo = maxOne;
                maxOne =n;
             else if(maxTwo < n)
                maxTwo = n;
            
        
        System.out.println("Second Max Number: "+maxTwo);
    

    public static void main(String a[])
        int num[] = 10,20,30,40,50,60,70;
        SecondMaxNumbers sec = new SecondMaxNumbers();
        tmn.printTwoMaxNumbers(num);
    

【讨论】:

【参考方案19】:

O(n/2) 中的第二大

public class SecMaxNum 

    // second Largest number with O(n/2)
    /**
     * @author Rohan Kamat
     * @Date Feb 04, 2016
     */
    public static void main(String[] args) 
        int[] input =  1, 5, 10, 11, 11, 4, 2, 8, 1, 8, 9, 8 ;
        int large = 0, second = 0;

        for (int i = 0; i < input.length - 1; i = i + 2) 
            // System.out.println(i);
            int fist = input[i];
            int sec = input[i + 1];
            if (sec >= fist) 
                int temp = fist;
                fist = sec;
                sec = temp;
            
            if (fist >= second) 
                if (fist >= large) 
                    large = fist;
                 else 
                    second = fist;
                

            

            if (sec >= second) 
                if (sec >= large) 
                    large = sec;
                 else 
                    second = sec;
                
            
        
    

【讨论】:

您好,您的解决方案不是 O(n/2),因为比较的时间决定了这个问题的计算复杂度。即使你的迭代次数是 n/2,但每次迭代你都会比较超过 2 次,所以整个比较的次数仍然超过 n 次。顺便说一句,当我们谈论计算复杂度时,我们通常会忽略系数,O(0.5n)、O(2n) 和 O(4n),它们都可以看作是同一个类。【参考方案20】:

公共类 SecondHighInIntArray

public static void main(String[] args) 
    int[] intArray=new int[]2,2,1;
            //2,2,1,12,3,7,9,-1,-5,7;
    int secHigh=findSecHigh(intArray);
    System.out.println(secHigh);


private static int findSecHigh(int[] intArray) 

    int highest=Integer.MIN_VALUE;
    int sechighest=Integer.MIN_VALUE;
    int len=intArray.length;
    for(int i=0;i<len;i++)
    
        if(intArray[i]>highest)
        
            sechighest=highest;
            highest=intArray[i];
            continue;
        

        if(intArray[i]<highest && intArray[i]>sechighest)
        
            sechighest=intArray[i];
            continue;
        


    
    return sechighest;

【讨论】:

【参考方案21】:

请试试这个:使用此方法,您可以对数组中的第二大数进行罚款,即使数组包含随机数。第一个循环用于解决数组的第一个索引最大的问题。

public class secondLargestnum 

    public static void main(String[] args) 
        // TODO Auto-generated method stub
        int[] array = new int[6];
        array[0] = 10;
        array[1] = 80;
        array[2] = 5;
        array[3] = 6;
        array[4] = 50;
        array[5] = 60;
        int tem = 0;
        for (int i = 0; i < array.length; i++) 
            if (array[0]>array[i]) 
                tem = array[0];
            array[0] = array[array.length-1];
            array[array.length-1] = tem;
            
        
        Integer largest = array[0];
        Integer second_largest = array[0];

        for (int i = 0; i < array.length; i++) 

            if (largest<array[i]) 
                second_large = largest;
                largest = array[i];
            
            else if (second_large<array[i]) 
                second_large = array[i];

            

        
System.out.println("largest number "+largest+" and second largest number "+second_largest);

    


【讨论】:

请edit 提供更多信息。纯代码和“试试这个”的答案是discouraged,因为它们不包含可搜索的内容,也没有解释为什么有人应该“试试这个”。我们在这里努力成为知识的资源。【参考方案22】:
private static int SecondBiggest(int[] vector)

    if (vector == null)
    
        throw new ArgumentNullException("vector");
    
    if (vector.Length < 2)
    
        return int.MinValue;
    

    int max1 = vector[0];
    int max2 = vector[1];
    for (int i = 2; i < vector.Length; ++i)
    
        if (max1 > max2 && max1 != vector[i])
        
            max2 = Math.Max(max2, vector[i]);
        
        else if (max2 != vector[i])
        
            max1 = Math.Max(max1, vector[i]);
        
    
    return Math.Min(max1, max2);

这会将重复的数字视为相同的数字。如果您希望所有最大的和第二大的都重复,您可以更改条件检查。

【讨论】:

【参考方案23】:

问题: 问题是要获得第二大数组元素。

观察: 第二大数定义为从数组中的最大元素中减去后具有最小差异的数。

解决方案: 这是一个两通解决方案。第一遍是找到最大数量。第二遍是找到与其他数组元素相比与最大元素差异最小的元素。示例:在数组 [2, 3, 6, 6, 5] 最大值 = 6 和第二最大值 = 5 中,因为它与最大元素 6 - 5 = 1 的差异最小,所以第二大的解 = 5

function printSecondMax(myArray) 
  var x, max = myArray[0];
  // Find maximum element 
  for(x in myArray)
     if(max < myArray[x])
        max = myArray[x];
     
  
  var secondMax = myArray[0], diff = max - secondMax;
  // Find second max, an element that has min diff with the max
  for(x in myArray)
    if(diff != 0 && (max - myArray[x]) != 0 && diff > (max - myArray[x]))
        secondMax = myArray[x];
        diff = max - secondMax;
    
  
  console.log(secondMax);

复杂度:O(n),这是最简单的方法。

为了更有效地找到最大元素,可以查看max heap,调用 max-heapify 将花费 O(log n) 时间来找到最大值,然后弹出顶部元素给出最大值。要获得第二个最大值,请在弹出顶部后进行 max-heapify 并继续弹出直到您得到一个小于最大值的数字。这将是第二个最大值。该解决方案具有 O(n log n) 复杂度。

【讨论】:

【参考方案24】:

如果这个问题来自面试官,那么请不要使用排序技术或不要使用任何内置方法,如 Arrays.sort 或 Collection.sort。这个问题的目的是您的解决方案在性能方面的优化程度,因此最好的选择就是使用您自己的逻辑和 O(n-1) 实现来实现。以下代码仅供初学者使用,不适合有经验的人。

  public void printLargest()


    int num[] = 900,90,6,7,5000,4,60000,20,3;

    int largest = num[0];

    int secondLargest = num[1];

    for (int i=1; i<num.length; i++)
    
        if(largest < num[i])
        
            secondLargest = largest;
            largest = num[i];


        
        else if(secondLargest < num[i])
            secondLargest = num[i];
        
    
    System.out.println("Largest : " +largest);
    System.out.println("Second Largest : "+secondLargest);

【讨论】:

【参考方案25】:
public class SecondandThirdHighestElement 
    public static void main(String[] args) 
        int[] arr = 1,1,2,3,8,1,2,3,3,3,2,3,101,6,6,7,8,8,1001,99,1,0;
        // create three temp variable and store arr of first element in that temp variable so that it will compare with other element
        int firsttemp = arr[0];
        int secondtemp = arr[0];
        int thirdtemp = arr[0];
        //check and find first highest value from array by comparing with other elements if found than save in the first temp variable 
        for (int i = 0; i < arr.length; i++) 
            if(firsttemp <arr[i])
                firsttemp =  arr[i];
            //if

        //for
        //check and find the second highest variable by comparing with other elements in an array and find the element and that element should be smaller than first element array
        for (int i = 0; i < arr.length; i++) 
            if(secondtemp < arr[i] && firsttemp>arr[i])
                secondtemp = arr[i];
            //if
        //for
        //check and find the third highest variable by comparing with other elements in an array and find the element and that element should be smaller than second element array

        for (int i = 0; i < arr.length; i++) 
            if(thirdtemp < arr[i] && secondtemp>arr[i])
                thirdtemp = arr[i];
            //if
        //for

        System.out.println("First Highest Value:"+firsttemp);
        System.out.println("Second Highest Value:"+secondtemp);
        System.out.println("Third Highest  Value:"+thirdtemp);

    //main
//class

【讨论】:

【参考方案26】:

我提供的解决方案不在 JAVA 程序中(用 javascript 编写),但它需要 o(n/2) 次迭代才能找到最高和第二高的数字。 工作提琴手链接Fiddler link

 var num=[1020215,2000,35,2,54546,456,2,2345,24,545,132,5469,25653,0,2315648978523];
var j=num.length-1;
var firstHighest=0,seoncdHighest=0;
num[0] >num[num.length-1]?(firstHighest=num[0],seoncdHighest=num[num.length-1]):(firstHighest=num[num.length-1],   seoncdHighest=num[0]);
j--;
for(var i=1;i<=num.length/2;i++,j--)

   if(num[i] < num[j] )
   
          if(firstHighest < num[j])
          seoncdHighest=firstHighest;
           firstHighest= num[j];
          
           else if(seoncdHighest < num[j] ) 
               seoncdHighest= num[j];

           
   
   else 
       if(firstHighest < num[i])
       
           seoncdHighest=firstHighest;
           firstHighest= num[i];

       
       else if(seoncdHighest < num[i] ) 
            seoncdHighest= num[i];

       
   

         

【讨论】:

【参考方案27】:
static int secondLargest(int[] input)
    int largest , secondlargest;

    if(input[0]>input[1])
    
        largest=input[0];
        secondlargest = input[1];
    
    else
    
        secondlargest = input[0];
        largest =input[1];
    
    for(int i =2 ;i<input.length;i++)
        if(input[i]>largest)
        
            secondlargest  = largest;
            largest = input[i];
        
        else if(input[i]>secondlargest)
            secondlargest = input[i];
        

    
    return secondlargest;

【讨论】:

【参考方案28】:

如果我们可以使用内置函数,我认为要找到第二个最高不,我们需要这些行

int[] randomIntegers = 1, 5, 4, 2, 8, 1, 1, 6, 7, 8, 9;
    Arrays.sort(randomIntegers);
    System.out.println(randomIntegers[randomIntegers.length-2]);

【讨论】:

【参考方案29】:
Scanner sc = new Scanner(System.in);

System.out.println("\n number of input sets::");
int value=sc.nextInt();
System.out.println("\n input sets::");
int[] inputset; 

inputset = new int[value];
for(int i=0;i<value;i++)

    inputset[i]=sc.nextInt();

int maxvalue=inputset[0];
int secondval=inputset[0];
for(int i=1;i<value;i++)

    if(inputset[i]>maxvalue)
   
        maxvalue=inputset[i];
    

for(int i=1;i<value;i++)

    if(inputset[i]>secondval && inputset[i]<maxvalue)
    
        secondval=inputset[i];
    

System.out.println("\n maxvalue"+ maxvalue);
System.out.println("\n secondmaxvalue"+ secondval);

【讨论】:

【参考方案30】:

这是我在 C 中的答案,O(N) 复杂度时间。 数组只传递一次,只有三个变量。 该解决方案非常直观且易于理解。

 #include <stdio.h>

    int second(int arr[],int size)
    
        int i, max , secondmax;

        if (arr[0] > arr[1])
            max = arr[0];
            secondmax = arr[1];
         else 
            max = arr[1];
            secondmax = arr[0];
        
        for (i = 2; i < size; i++)
        
            if ((arr[i] < max) && (arr[i] < secondmax)) 
                continue;
            
            if ((arr[i] < max) && (arr[i] > secondmax)) 
                secondmax = arr[i];
                continue;
            
            if ((arr[i] > max)) 
                secondmax = max;
                max = arr[i];
                continue;
            
        
        return secondmax;
    
    void main()
    
        int arr[] =  1,10,5,7;
        int size = sizeof(arr) / sizeof(arr[0]);
        int secondmax = second(arr,size);
        printf("%d \n\n", secondmax);
    

【讨论】:

问题是关于 Java 的。这个答案不是。

以上是关于查找数组中第二大的数字的主要内容,如果未能解决你的问题,请参考以下文章

LeetCode 1796. 字符串中第二大的数字

LeetCode 1796. 字符串中第二大的数字

Python|字符串中第二大的数字

LeetCode刷题简单-1796-字符串中第二大的数字

LeetCode刷题简单-1796-字符串中第二大的数字

LeetCode刷题简单-1796-字符串中第二大的数字