File tree Expand file tree Collapse file tree 1 file changed +64
-0
lines changed Expand file tree Collapse file tree 1 file changed +64
-0
lines changed Original file line number Diff line number Diff line change
1
+ package me .ramswaroop .misc ;
2
+
3
+ import java .io .BufferedReader ;
4
+ import java .io .FileReader ;
5
+ import java .io .IOException ;
6
+ import java .util .ArrayList ;
7
+ import java .util .List ;
8
+
9
+ /**
10
+ * Created by IntelliJ IDEA.
11
+ *
12
+ * @author: ramswaroop
13
+ * @date: 9/15/15
14
+ * @time: 11:15 PM
15
+ */
16
+ public class Parenthesis {
17
+
18
+ public static String isWellFormed (String input ) {
19
+ int len = input .length () - 1 ;
20
+ for (int i = 0 ; i < len / 2 ; i ++) {
21
+ if (input .charAt (0 ) != input .charAt (len - i - 1 )) {
22
+ return "False" ;
23
+ }
24
+ }
25
+ return "True" ;
26
+ }
27
+
28
+ public static void areParenthesisWellFormed (String filename ) {
29
+ List <String > input = readFile (filename );
30
+ for (int i = 0 ; i < input .size (); i ++) {
31
+ isWellFormed (input .get (i ));
32
+ }
33
+ }
34
+
35
+ public static List <String > readFile (String filename ) {
36
+ List <String > input = new ArrayList <>();
37
+ BufferedReader br = null ;
38
+
39
+ try {
40
+
41
+ String sCurrentLine ;
42
+
43
+ br = new BufferedReader (new FileReader (filename ));
44
+
45
+ while ((sCurrentLine = br .readLine ()) != null ) {
46
+ input .add (sCurrentLine );
47
+ }
48
+
49
+ } catch (IOException e ) {
50
+ e .printStackTrace ();
51
+ } finally {
52
+ try {
53
+ if (br != null ) br .close ();
54
+ } catch (IOException ex ) {
55
+ ex .printStackTrace ();
56
+ }
57
+ }
58
+ return input ;
59
+ }
60
+
61
+ public static void main (String a []) {
62
+ areParenthesisWellFormed (a [0 ]);
63
+ }
64
+ }
You can’t perform that action at this time.
0 commit comments