Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

valid parentheses leetcode solution java

HashMap<Character, Character> map = new HashMap<Character, Character>();
	map.put('(', ')');
	map.put('[', ']');
	map.put('{', '}');
 
	Stack<Character> stack = new Stack<Character>();
 
	for (int i = 0; i < s.length(); i++) {
		char curr = s.charAt(i);
 
		if (map.keySet().contains(curr)) {
			stack.push(curr);
		} else if (map.values().contains(curr)) {
			if (!stack.empty() && map.get(stack.peek()) == curr) {
				stack.pop();
			} else {
				return false;
			}
		}
	}
 
	return stack.empty();
Comment

PREVIOUS NEXT
Code Example
Java :: calling static method in java 
Java :: advantages of using java 
Java :: array methods in java 
Java :: generics Interface in java 
Java :: list of arrays 
Java :: java class 
Java :: how to encrypt password in properties file in spring boot 
Java :: java heap example 
Java :: Java float Keyword 
Java :: java mahout get clusters centers 
Java :: java code to get all leaf nodes of a xml 
Java :: java loop find index 
Java :: madhava kripa 
Java :: getsmallestnumber 
Java :: java and python begineers mcq with answers 
Java :: varstatus foreach jsp 
Java :: Java extends and implements clause 
Java :: Longest decreasing subsequence in java 
Java :: expression régulière seulement un espace java 
Java :: open google maps cycling navigation intent 
Java :: taking user input in array in java using constructor 
Java :: inheritance setter and getter in java 
Java :: create object of hashMap with integer key and String value 
Java :: use flatpickr in javascripot 
Java :: success listener with Glide Android java 
Java :: Zooming an Image using OpenCV in Java 
Java :: how to find a specific character in a string using array 
Java :: priority queue java remove 
Java :: android studio press button programmatically 
Java :: remove first character from string java 
ADD CONTENT
Topic
Content
Source link
Name
2+2 =