Skip to content

Commit 981ded0

Browse files
refactor 439
1 parent 43cec01 commit 981ded0

File tree

1 file changed

+0
-46
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+0
-46
lines changed

src/main/java/com/fishercoder/solutions/_439.java

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -3,52 +3,6 @@
33
import java.util.ArrayDeque;
44
import java.util.Deque;
55

6-
/**
7-
* 439. Ternary Expression Parser
8-
*
9-
* Given a string representing arbitrarily nested ternary expressions, calculate the result of the expression.
10-
* You can always assume that the given expression is valid and only consists of digits 0-9, ?, :, T and F (T and F represent True and False respectively).
11-
12-
Note:
13-
14-
The length of the given string is ≤ 10000.
15-
Each number will contain only one digit.
16-
The conditional expressions group right-to-left (as usual in most languages).
17-
The condition will always be either T or F. That is, the condition will never be a digit.
18-
The result of the expression will always evaluate to either a digit 0-9, T or F.
19-
20-
Example 1:
21-
22-
Input: "T?2:3"
23-
24-
Output: "2"
25-
26-
Explanation: If true, then result is 2; otherwise result is 3.
27-
28-
29-
Example 2:
30-
31-
Input: "F?1:T?4:5"
32-
33-
Output: "4"
34-
35-
Explanation: The conditional expressions group right-to-left. Using parenthesis, it is read/evaluated as:
36-
37-
"(F ? 1 : (T ? 4 : 5))" "(F ? 1 : (T ? 4 : 5))"
38-
-> "(F ? 1 : 4)" or -> "(T ? 4 : 5)"
39-
-> "4" -> "4"
40-
Example 3:
41-
42-
Input: "T?T?F:5:3"
43-
44-
Output: "F"
45-
46-
Explanation: The conditional expressions group right-to-left. Using parenthesis, it is read/evaluated as:
47-
48-
"(T ? (T ? F : 5) : 3)" "(T ? (T ? F : 5) : 3)"
49-
-> "(T ? F : 3)" or -> "(T ? F : 5)"
50-
-> "F" -> "F"
51-
*/
526
public class _439 {
537

548
public static class Solution1 {

0 commit comments

Comments
 (0)