LeetCode知识点总结 - 2011

LeetCode 2011. Final Value of Variable After Performing Operations

考点 难度
Simulation Easy
题目

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-- decrements the value of the variable X by 1.
Initially, the value of X is 0.

Given an array of strings operations containing a list of operations, return the final value of X after performing all the operations.

思路

按照题上描述做就可以。

答案
public int finalValueAfterOperations(String[] operations) {
    	int val = 0;
    	for(int i=0;i

你可能感兴趣的:(LeetCode,leetcode,算法,职场和发展)