Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static int solution(String S) {
- for(int i=1; i<S.length();i++){
- String left = S.substring(0,i);
- String right = S.substring(i,S.length());
- System.out.print("On left:"+ numberChars(left,'('));
- System.out.println(" .On right:"+ numberChars(right,')'));
- int openOnLeft= numberChars(left,'(');
- int closedOnRight= numberChars(right,')');
- if((openOnLeft-closedOnRight)==0){
- System.out.println("Found on:"+i);
- return i;
- }
- }
- return 0;
- }
- private static int numberChars(String str, char find){
- int numFound=0;
- for(char c:str.toCharArray()){
- if(c== find)
- numFound++;
- }
- return numFound;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement