Skip to content

Commit 2a1caa1

Browse files
authored
Improved task 2011.
1 parent 33c91a7 commit 2a1caa1

File tree

1 file changed

+18
-26
lines changed
  • src/main/java/g2001_2100/s2011_final_value_of_variable_after_performing_operations

1 file changed

+18
-26
lines changed

src/main/java/g2001_2100/s2011_final_value_of_variable_after_performing_operations/readme.md

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,70 +4,62 @@ Easy
44

55
There is a programming language with only **four** operations and **one** variable `X`:
66

7-
* `++X` and `X++` **increments** the value of the variable `X` by `1`.
8-
* `--X` and `X--` **decrements** the value of the variable `X` by `1`.
7+
* `++X` and `X++` **increments** the value of the variable `X` by `1`.
8+
* `--X` and `X--` **decrements** the value of the variable `X` by `1`.
99

1010
Initially, the value of `X` is `0`.
1111

12-
Given an array of strings `operations` containing a list of operations, return the final value of `X` *after performing all the operations* .
12+
Given an array of strings `operations` containing a list of operations, return _the **final** value of_ `X` _after performing all the operations_.
1313

1414
**Example 1:**
1515

1616
**Input:** operations = ["--X","X++","X++"]
1717

1818
**Output:** 1
1919

20-
**Explanation:**
20+
**Explanation:** The operations are performed as follows:
2121

22-
The operations are performed as follows:
22+
Initially, X = 0.
2323

24-
Initially, X = 0.
24+
--X: X is decremented by 1, X = 0 - 1 = -1.
2525

26-
--X: X is decremented by 1, X = 0 - 1 = -1.
26+
X++: X is incremented by 1, X = -1 + 1 = 0.
2727

28-
X++: X is incremented by 1, X = -1 + 1 = 0.
29-
30-
X++: X is incremented by 1, X = 0 + 1 = 1.
28+
X++: X is incremented by 1, X = 0 + 1 = 1.
3129

3230
**Example 2:**
3331

3432
**Input:** operations = ["++X","++X","X++"]
3533

3634
**Output:** 3
3735

38-
**Explanation:**
39-
40-
The operations are performed as follows:
36+
**Explanation:** The operations are performed as follows:
4137

42-
Initially, X = 0.
38+
Initially, X = 0.
4339

44-
++X: X is incremented by 1, X = 0 + 1 = 1.
40+
++X: X is incremented by 1, X = 0 + 1 = 1.
4541

4642
++X: X is incremented by 1, X = 1 + 1 = 2.
4743

48-
X++: X is incremented by 1, X = 2 + 1 = 3.
44+
X++: X is incremented by 1, X = 2 + 1 = 3.
4945

5046
**Example 3:**
5147

5248
**Input:** operations = ["X++","++X","--X","X--"]
5349

5450
**Output:** 0
5551

56-
**Explanation:**
52+
**Explanation:** The operations are performed as follows:
5753

58-
The operations are performed as follows:
54+
Initially, X = 0.
5955

60-
Initially, X = 0.
61-
62-
X++: X is incremented by 1, X = 0 + 1 = 1.
56+
X++: X is incremented by 1, X = 0 + 1 = 1.
6357

6458
++X: X is incremented by 1, X = 1 + 1 = 2.
6559

66-
--X: X is decremented by 1, X = 2 - 1 = 1.
67-
68-
X--: X is decremented by 1, X = 1 - 1 = 0.
60+
--X: X is decremented by 1, X = 2 - 1 = 1. X--: X is decremented by 1, X = 1 - 1 = 0.
6961

7062
**Constraints:**
7163

72-
* `1 <= operations.length <= 100`
73-
* `operations[i]` will be either `"++X"`, `"X++"`, `"--X"`, or `"X--"`.
64+
* `1 <= operations.length <= 100`
65+
* `operations[i]` will be either `"++X"`, `"X++"`, `"--X"`, or `"X--"`.

0 commit comments

Comments
 (0)