Why there is a nullpointer problem? java


  • 0
    C

    public class Solution {
    public int longestValidParentheses(String s) {

        int size=s.length();
        if(size==0||size==1) return size;
        String va=null;
        int i=0;
        for(int j=1;j<size;){
            if(s.charAt(i)=='('){
                if(s.charAt(j)==')'){
                    va+="()";
                    i=j;
                    j++;
                }else j++;
                
            }else {
                i++;
                j++;
            }
        }
        
        return va.length();
        
    }
    

    }


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.