codekata (week2-day3)

lazy corder·2022년 5월 14일
0

function isValid(s) {   

	if (s.length % 2) {    
		return false;  
	}  
	
	const openingBrackets = []  
	const obj = {    
		"{" : "}",    
		"(" : ")",    
		"[" : "]"  
		}  

	for (let i=0 ; i<s.length; i++){    

	if (obj[s[i]] !== undefined){      
			openingBrackets.push(s[i]);    
	  } else if ( obj[openingBrackets.pop()] !== s[i] ) {    
 
	   return false;    
    }  
	}  
	return true;

0개의 댓글