Skip to content

Commit 4a1ca96

Browse files
committed
feat: add typescript solution to lc problem: No.2011.Final Value of Variable After Performing Operations
1 parent 7f20f00 commit 4a1ca96

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

solution/2000-2099/2011.Final Value of Variable After Performing Operations/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,18 @@ X--:X 减 1 ,X = 1 - 1 = 0
8888

8989
```
9090

91+
### **TypeScript**
92+
93+
```ts
94+
function finalValueAfterOperations(operations: string[]): number {
95+
let ans = 0;
96+
for (let operation of operations) {
97+
ans += (operation.includes('+') ? 1 : -1)
98+
}
99+
return ans;
100+
};
101+
```
102+
91103
### **...**
92104

93105
```

solution/2000-2099/2011.Final Value of Variable After Performing Operations/README_EN.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,18 @@ X--: X is decremented by 1, X = 1 - 1 = 0.
7878

7979
```
8080

81+
### **TypeScript**
82+
83+
```ts
84+
function finalValueAfterOperations(operations: string[]): number {
85+
let ans = 0;
86+
for (let operation of operations) {
87+
ans += (operation.includes('+') ? 1 : -1)
88+
}
89+
return ans;
90+
};
91+
```
92+
8193
### **...**
8294

8395
```
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
function finalValueAfterOperations(operations: string[]): number {
2+
let ans = 0;
3+
for (let operation of operations) {
4+
ans += (operation.includes('+') ? 1 : -1)
5+
}
6+
return ans;
7+
};

0 commit comments

Comments
 (0)