Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 67bed69

Browse files
author
Ram swaroop
committed
minor optimizations
1 parent 73620cf commit 67bed69

File tree

1 file changed

+6
-22
lines changed

1 file changed

+6
-22
lines changed

src/me/ramswaroop/misc/Parenthesis.java

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
import java.io.BufferedReader;
44
import java.io.FileReader;
55
import java.io.IOException;
6-
import java.util.ArrayList;
76
import java.util.EmptyStackException;
8-
import java.util.List;
97

108
/**
119
* Created by IntelliJ IDEA.
@@ -57,40 +55,26 @@ public static boolean isWellFormed(String input) {
5755

5856
return stack.isEmpty();
5957
}
60-
61-
/**
62-
* Checks if the parenthesis are well-formed for the entire input.
63-
*
64-
* @param filePath
65-
*/
66-
public static void areParenthesisWellFormed(String filePath) {
67-
List<String> input = readFile(filePath);
68-
for (int i = 0; i < input.size(); i++) {
69-
System.out.println(isWellFormed(input.get(i)) ? "True" : "False");
70-
}
71-
}
72-
58+
7359
/**
74-
* Reads the file specified in {@param filePath}.
60+
* Reads the file specified in {@param filePath} line by line
61+
* and checks if parenthesis are well-formed or not.
7562
*
7663
* @param filePath
77-
* @return list of strings in each line of the file
7864
*/
79-
public static List<String> readFile(String filePath) {
65+
public static void readFile(String filePath) {
8066

81-
List<String> input = new ArrayList<>();
8267
try (BufferedReader br = new BufferedReader(new FileReader(filePath))) {
8368

8469
String line;
8570

8671
while ((line = br.readLine()) != null) {
87-
input.add(line);
72+
System.out.println(isWellFormed(line) ? "True" : "False");
8873
}
8974

9075
} catch (IOException e) {
9176
e.printStackTrace();
9277
}
93-
return input;
9478
}
9579

9680
/**
@@ -99,7 +83,7 @@ public static List<String> readFile(String filePath) {
9983
* @param a
10084
*/
10185
public static void main(String a[]) {
102-
areParenthesisWellFormed(a[0]);
86+
readFile(a[0]);
10387
System.exit(0);
10488
}
10589
}

0 commit comments

Comments
 (0)