540.Compare Prefix and Postfix Increment and Decrement
Easy
Given an integer
x, run a = x++, b = ++x, c = x-- and d = --x in that order and return [a, b, c, d, x].
Increment and decrementIncrement / DecrementThe ++ and -- operators, which add or subtract 1 from a variable in place. operators change a variable by one, but where you put them matters. In prefixPrefix (++x)The variable is changed first and the expression gives the new value. form the change happens before the value is used; in postfixPostfix (x++)The expression gives the current value, and the variable is changed afterwards. form it happens after. Python has no ++ or --, so its solutions use the expanded form, which is also the clearest way to see what the operators do.
Example 1:
Input: x = 5
Output: [5,7,7,5,5]
Example 2:
Input: x = -3
Output: [-3,-1,-1,-3,-3]
+ 4 hidden test cases run on Submit.
Constraints:
- ●
-1000 ≤ x ≤ 1000
x =
5