Skip to content

Commit e0ee629

Browse files
committed
Add solution #2011
1 parent 4f08ac4 commit e0ee629

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@
211211
1929|[Concatenation of Array](./1929-concatenation-of-array.js)|Easy|
212212
1935|[Maximum Number of Words You Can Type](./1935-maximum-number-of-words-you-can-type.js)|Easy|
213213
2000|[Reverse Prefix of Word](./2000-reverse-prefix-of-word.js)|Easy|
214+
2011|[Final Value of Variable After Performing Operations](./2011-final-value-of-variable-after-performing-operations.js)|Easy|
214215
2016|[Maximum Difference Between Increasing Elements](./2016-maximum-difference-between-increasing-elements.js)|Easy|
215216

216217
## License
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* 2011. Final Value of Variable After Performing Operations
3+
* https://leetcode.com/problems/final-value-of-variable-after-performing-operations/
4+
* Difficulty: Easy
5+
*
6+
* There is a programming language with only four operations and one variable X:
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.
9+
*
10+
* Initially, the value of X is 0.
11+
*
12+
* Given an array of strings operations containing a list of operations, return the
13+
* final value of X after performing all the operations.
14+
*/
15+
16+
/**
17+
* @param {string[]} operations
18+
* @return {number}
19+
*/
20+
var finalValueAfterOperations = function(operations) {
21+
return operations
22+
.map(n => n.includes('++') ? 1 : -1)
23+
.reduce((sum, n) => sum + n, 0);
24+
};

0 commit comments

Comments
 (0)