LeetCode Entry

2011. Final Value of Variable After Performing Operations

20.10.2025 easy 2025 kotlin rust

do ++ or -- operation from 0

2011. Final Value of Variable After Performing Operations easy blog post substack youtube

1476e184-c73b-4b5f-a496-0feaf1535283 (1).webp

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 _
    }