今天参加小米二面,面试官让手撕一道算法题,感觉这道算法题挺有意义的,所以还是分享出来。题目如下 这道题目的思路可能会很简单,但是里面的细节可能会要重视一下,我自己写的代码如下,代码能够全部通过。话不多说,直接上代码。 public static void main ( String [] args ) { // TODO Auto-generated method stub Scanner sc = new Scanner ( System . in ); String s = sc . nextLine (); String sb = "" ; //StringBuilder sb = new StringBuilder(); StringBuilder sb1 = new StringBuilder (); char [] ch = s . toCharArray (); for ( int i = 0 ; i < ch . length ; i ++){ if ( ch [ i ]>= '0' && ch [ i ]<= '9' ){ sb1 . append ( ch [ i ]); } else { if ( sb1 . length ()> sb . length ()){ sb = sb1 . toString (); } sb1 . delete ( 0 , sb1