File tree Expand file tree Collapse file tree 1 file changed +0
-7
lines changed
src/main/java/g1701_1800/s1763_longest_nice_substring Expand file tree Collapse file tree 1 file changed +0
-7
lines changed Original file line number Diff line number Diff line change 88
99public class Solution {
1010 public String longestNiceSubstring (String s ) {
11-
1211 int index = isNotNiceString (s );
13-
1412 if (index == -1 ) {
1513 return s ;
1614 }
17-
1815 String left = longestNiceSubstring (s .substring (0 , index ));
1916 String right = longestNiceSubstring (s .substring (index + 1 ));
20-
2117 return left .length () >= right .length () ? left : right ;
2218 }
2319
2420 private int isNotNiceString (String s ) {
2521 Set <Character > set = new HashSet <>();
26-
2722 for (char c : s .toCharArray ()) {
2823 set .add (c );
2924 }
30-
3125 for (int i = 0 ; i < s .length (); i ++) {
3226 char c = s .charAt (i );
3327 if (!set .contains (Character .toLowerCase (c ))
3428 || !set .contains (Character .toUpperCase (c ))) {
3529 return i ;
3630 }
3731 }
38-
3932 return -1 ;
4033 }
4134}
You can’t perform that action at this time.
0 commit comments