GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — leetcode/java/415_Add_Strings.java at master · gsty/leetcode Expand file tree/ Copy path415_Add_Strings.javaMore file actions 15 lines (15 loc) · 645 Bytes / Copy path415_Add_Strings.javaFile metadata and controls15 lines (15 loc) · 645 Bytes 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 public class Solution { public String addStrings(String num1, String num2) { StringBuilder sb = new StringBuilder(); int carry = 0; // condition is great // https://leetcode.com/problems/add-strings/discuss/90436/Straightforward-Java-8-main-lines-25ms for(int i = num1.length() - 1, j = num2.length() - 1; i >= 0 || j >= 0 || carry == 1; i--, j--){ int x = i < 0 ? 0 : num1.charAt(i) - '0'; int y = j < 0 ? 0 : num2.charAt(j) - '0'; sb.append((x + y + carry) % 10); carry = (x + y + carry) / 10; } return sb.reverse().toString(); } } |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |