Compare commits
No commits in common. 'recursive-iterator' and 'master' have entirely different histories.
recursive-
...
master
@ -1,35 +1,20 @@
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.function.BiPredicate;
|
import java.io.*;
|
||||||
|
import java.math.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Template code to help you parse the standard input
|
||||||
|
* according to the problem statement.
|
||||||
|
**/
|
||||||
class Solution {
|
class Solution {
|
||||||
|
|
||||||
// best readable version, also without dark ASCII code tricks
|
|
||||||
private static final BiPredicate<Integer, Integer> BRACKETS_MATCH = ( c1, c2 ) -> ( c1 != null && c2 != null )
|
|
||||||
&& (( c1 == '(' && c2 == ')' ) || ( c1 == '[' && c2 == ']' ) || ( c1 == '{' && c2 == '}' ));
|
|
||||||
|
|
||||||
// code your solution here
|
|
||||||
private static boolean checkNextChar( Deque<Integer> stack, Iterator<Integer> iter ) {
|
|
||||||
if ( ! iter.hasNext() ) return stack.isEmpty();
|
|
||||||
|
|
||||||
int c = iter.next();
|
|
||||||
if ( BRACKETS_MATCH.test( stack.peek(), c )) {
|
|
||||||
stack.pop();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
stack.push( c );
|
|
||||||
}
|
|
||||||
|
|
||||||
return checkNextChar( stack, iter );
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main( String[] args ) {
|
public static void main( String[] args ) {
|
||||||
// hint: read values via Scanner methods
|
Scanner in = new Scanner( System.in );
|
||||||
var inputLine = new Scanner( System.in ).nextLine();
|
// read values with in.next...() methods
|
||||||
|
|
||||||
var stack = new ArrayDeque<Integer>( inputLine.length() );
|
// code your solution here
|
||||||
var iter = inputLine.chars().iterator();
|
|
||||||
|
|
||||||
// Write result with System.out.println()
|
// Write result with System.out.println()
|
||||||
System.out.println( checkNextChar( stack, iter ) );
|
System.out.println( "value" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue