Parenthesis/Brackets Matching using Stack algorithm

前端 未结 30 2715
你的背包
你的背包 2020-11-27 11:39

For example if the parenthesis/brackets is matching in the following:

({})
(()){}()
()

and so on but if the parenthesis/brackets is not mat

30条回答
  •  执笔经年
    2020-11-27 12:18

    import java.util.*;
    
    public class Parenthesis
    
     {
    
        public static void main(String...okok)
    
        {
            Scanner sc= new Scanner(System.in);
            String str=sc.next();
            System.out.println(isValid(str));
    
        }
        public static int isValid(String a) {
            if(a.length()%2!=0)
            {
    
                return 0;
            }
            else if(a.length()==0)
            {
    
                return 1;
            }
            else
            {
    
                char c[]=a.toCharArray();
                Stack stk =  new Stack();
                for(int i=0;i

提交回复
热议问题