C++中+ =和= +运算符之间的区别?

asx*_*asx 0 c++ operators

C++中+ =和= +运算符有什么区别?我已经看到一个解决方案,通过使用= +运算符找到二叉树的深度.

class Solution { 
public:
int maxDepth(TreeNode* root) {
    int l,r;
    if(root == NULL) {
        return 0;
    }
    else {
        l =+ maxDepth(root->left);
        r =+ maxDepth(root->right);
    }
    if (l>r)
    return (l+1);
    else
    return (r+1);
}
};
Run Code Online (Sandbox Code Playgroud)

Sud*_*hoo 9

+ =表示它将增加lValue右侧值.

= +表示它会将右侧值(带符号)分配给"lValue"

int a = 5;
a += 1;
cout << a; // Here it will print 6.

a =+ 1;
cout << a; // Here it will print 1 (+1).

a =- 1;
cout << a; // Here it will print -1.
Run Code Online (Sandbox Code Playgroud)

希望这可以帮助.