-
Recent Posts
Archives
calendar
December 2025 M T W T F S S 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 Categories
Meta
Tag Cloud
Author Archives: codingfan
pair match
01.import java.util.Scanner; 02.import java.util.Stack; 03. 04.public class Main{ 05.static Stack<Character> str=new Stack<Character>(); 06.public static boolean match(String s) 07.{ 08.//str.push(s.charAt(0)); 09.char ch; 10.boolean flag=true; 11.for(int i=0;i<s.length();i++) 12.{ 13.ch=s.charAt(i); 14.if(str.isEmpty()) 15.{ 16.str.push(ch); 17.continue; 18.} 19.if((ch==’]’&&str.peek()=='[‘)||(ch==’)’&&str.peek()=='(‘)) 20.{ 21.str.pop(); 22.} 23.else { 24.str.push(ch); 25.} … Continue reading
Posted in Uncategorized
Leave a comment