Move all solutions into separate directory (cleanup)

the beginning
This commit is contained in:
2023-10-06 03:14:09 -05:00
parent 5ed552fb17
commit 9e0c58faff
26 changed files with 9 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
// Accepted
// Runtime: 1 ms
// Memory Usage: 39.3 MB
// Submitted: January 15th, 2021
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode() {}
* ListNode(int val) { this.val = val; }
* ListNode(int val, ListNode next) { this.val = val; this.next = next; }
* }
*/
class Solution {
public ListNode addTwoNumbers(ListNode a, ListNode b) {
ListNode dummy = new ListNode(0);
ListNode cur = dummy;
int carry = 0;
while (a != null || b != null) {
int x = (a != null) ? a.val : 0;
int y = (b != null) ? b.val : 0;
int sum = carry + x + y;
carry = sum / 10;
cur.next = new ListNode(sum % 10);
cur = cur.next;
if (a != null) a = a.next;
if (b != null) b = b.next;
}
if (carry > 0)
cur.next = new ListNode(carry);
return dummy.next;
}
}

View File

@@ -0,0 +1,9 @@
{
"name": "Add Two Numbers",
"solutions": [
{
"name": "Java",
"path": "Solution.java"
}
]
}