using real Iterator<Integer> instead of fake CharacterIterator

recursive-iterator
Lothar Buchholz 5 years ago
parent 16ee5b632a
commit cd9a9e3936

@ -1,20 +1,35 @@
import java.util.*; import java.util.*;
import java.io.*; import java.util.function.BiPredicate;
import java.math.*;
/**
* Template code to help you parse the standard input
* according to the problem statement.
**/
class Solution { class Solution {
public static void main( String[] args ) { // best readable version, also without dark ASCII code tricks
Scanner in = new Scanner( System.in ); private static final BiPredicate<Integer, Integer> BRACKETS_MATCH = ( c1, c2 ) -> ( c1 != null && c2 != null )
// read values with in.next...() methods && (( c1 == '(' && c2 == ')' ) || ( c1 == '[' && c2 == ']' ) || ( c1 == '{' && c2 == '}' ));
// code your solution here // code your solution here
private static boolean checkNextChar( Deque<Integer> stack, Iterator<Integer> iter ) {
// Write result with System.out.println() if ( ! iter.hasNext() ) return stack.isEmpty();
System.out.println( "value" );
} 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 ) {
// hint: read values via Scanner methods
var inputLine = new Scanner( System.in ).nextLine();
var stack = new ArrayDeque<Integer>( inputLine.length() );
var iter = inputLine.chars().iterator();
// Write result with System.out.println()
System.out.println( checkNextChar( stack, iter ) );
}
} }

Loading…
Cancel
Save