반응형
https://leetcode.com/problems/final-value-of-variable-after-performing-operations/description/
Final Value of Variable After Performing Operations - LeetCode
Can you solve this real interview question? Final Value of Variable After Performing Operations - There is a programming language with only four operations and one variable X: * ++X and X++ increments the value of the variable X by 1. * --X and X-- decreme
leetcode.com

주어진 문자열에 맞춰 연산하는 문제.
class Solution {
fun finalValueAfterOperations(operations: Array<String>): Int {
var ans = 0;
for(i in 0 until operations.size){
if(operations[i].contains("--")) {
ans--;
} else{
ans++;
}
}
return ans;
}
}반응형
'IT > 알고리즘' 카테고리의 다른 글
| 75] Leetcode 2413. Smallest Even Multiple Kotlin (0) | 2023.04.10 |
|---|---|
| 74] Leetcode 2574. Left and Right Sum Differences Kotlin (0) | 2023.04.06 |
| 71] Leetcode 2469. Convert the Temperature (0) | 2023.04.04 |
| 70] Leetcode 1929. Concatenation of Array (0) | 2023.04.03 |
| 69] 프로그래머스 제곱수 판별하기 Kotlin (1) | 2023.03.21 |
댓글