LeetCode Entry
2011. Final Value of Variable After Performing Operations
do ++ or -- operation from 0
2011. Final Value of Variable After Performing Operations easy blog post substack youtube

Join me on Telegram
https://t.me/leetcode_daily_unstoppable/1148
Problem TLDR
do ++ or – operation from 0 #easy
Intuition
Simulate the process.
Approach
- just check ‘+’ in string
Complexity
-
Time complexity: \(O(n)\)
-
Space complexity: \(O(1)\)
Code
// 7ms
fun finalValueAfterOperations(o: Array<String>) =
2 * o.count { '+' in it } - o.size
// 1ms
pub fn final_value_after_operations(o: Vec<String>) -> i32 {
(o.join("").matches('+').count() - o.len()) as _
}