Accepted c#(sharp) solution. beat 90%


  • 0
                int i = a.Length - 1;
                int j = b.Length - 1;
                var result = "";
                int offSet = 0;
                while (i >= 0 || j >= 0)
                {
                    var firstValue = (i < 0) ? '0' : a[i];
                    var secondValue = (j < 0) ? '0' : b[j];
                    result = (firstValue + secondValue + offSet) % 2 + result;
                    offSet = ((firstValue + secondValue + offSet) / 2) - 48;
                    if (i >= 0) i--;
                    if (j >= 0) j--;
                }
                if (offSet != 0) result = "1" + result;
                return result;
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.