problemmediumalgorithmsadd-two-numbers-without-using-and-operatorsadd two numbers without using and operatorsaddtwonumberswithoutusingandoperatorsleetcode-371leetcode 371leetcode371add-two-numbers-without-using-arithmetic-operatorsadd two numbers without using arithmetic operatorsaddtwonumberswithoutusingarithmeticoperators

Sum of Two Integers

MediumUpdated: Sep 19, 2025
Practice on:
Video Solutions:

Problem

Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -.

Follow up

Write a function Add(a, b) that returns the sum of two integers without using any arithmetic operators (+, -, *, /, ++, --, etc.). Use only bitwise operators and shifts where needed.

Examples

Example 1

Input: a = 1, b = 2
Output: 3

Solution

See Method 1 and Method 2 of [Sum of two numbers using only bitwise operators](sum-of-two-numbers-using-only-bitwise-operators), and here is the video explaining this method in detail. Please check it out:

<div class="youtube-embed"><iframe src="https://www.youtube.com/embed/NJLGft5fS2Y" frameborder="0" allowfullscreen></iframe></div>

Continue Practicing

Comments