From f0925ed3fe44d88230c12edc052c6cee925a6f72 Mon Sep 17 00:00:00 2001 From: Diego M-R <95539668+diegomendez40@users.noreply.github.com> Date: Sat, 10 Feb 2024 08:08:58 +0100 Subject: [PATCH] Added 302 - Leetcode Added 302 - Leetcode - 0002 Add Two Numbers Changed directory name from 301 to 301 - Witch Jobsite --- {301 => 301 - Witch Jobsite}/.gitignore | 0 .../.mvn/wrapper/maven-wrapper.jar | Bin .../.mvn/wrapper/maven-wrapper.properties | 0 {301 => 301 - Witch Jobsite}/mvnw | 0 {301 => 301 - Witch Jobsite}/mvnw.cmd | 0 {301 => 301 - Witch Jobsite}/pom.xml | 0 .../jobsite/JobsiteApplication.java | 0 .../jobsite/controller/PostController.java | 0 .../flamencowitches/jobsite/model/Post.java | 0 .../jobsite/repository/PostRepository.java | 0 .../jobsite/repository/SearchRepository.java | 0 .../repository/SearchRepositoryImpl.java | 0 .../src/main/resources/application.properties | 0 .../jobsite/JobsiteApplicationTests.java | 0 .../0002 Add Two Numbers/AddTwoNumbers.java | 39 ++++++++++++++++++ 15 files changed, 39 insertions(+) rename {301 => 301 - Witch Jobsite}/.gitignore (100%) rename {301 => 301 - Witch Jobsite}/.mvn/wrapper/maven-wrapper.jar (100%) rename {301 => 301 - Witch Jobsite}/.mvn/wrapper/maven-wrapper.properties (100%) rename {301 => 301 - Witch Jobsite}/mvnw (100%) rename {301 => 301 - Witch Jobsite}/mvnw.cmd (100%) rename {301 => 301 - Witch Jobsite}/pom.xml (100%) rename {301 => 301 - Witch Jobsite}/src/main/java/com/diegom40/flamencowitches/jobsite/JobsiteApplication.java (100%) rename {301 => 301 - Witch Jobsite}/src/main/java/com/diegom40/flamencowitches/jobsite/controller/PostController.java (100%) rename {301 => 301 - Witch Jobsite}/src/main/java/com/diegom40/flamencowitches/jobsite/model/Post.java (100%) rename {301 => 301 - Witch Jobsite}/src/main/java/com/diegom40/flamencowitches/jobsite/repository/PostRepository.java (100%) rename {301 => 301 - Witch Jobsite}/src/main/java/com/diegom40/flamencowitches/jobsite/repository/SearchRepository.java (100%) rename {301 => 301 - Witch Jobsite}/src/main/java/com/diegom40/flamencowitches/jobsite/repository/SearchRepositoryImpl.java (100%) rename {301 => 301 - Witch Jobsite}/src/main/resources/application.properties (100%) rename {301 => 301 - Witch Jobsite}/src/test/java/com/diegom40/flamencowitches/jobsite/JobsiteApplicationTests.java (100%) create mode 100644 302 - Leetcode/0002 Add Two Numbers/AddTwoNumbers.java diff --git a/301/.gitignore b/301 - Witch Jobsite/.gitignore similarity index 100% rename from 301/.gitignore rename to 301 - Witch Jobsite/.gitignore diff --git a/301/.mvn/wrapper/maven-wrapper.jar b/301 - Witch Jobsite/.mvn/wrapper/maven-wrapper.jar similarity index 100% rename from 301/.mvn/wrapper/maven-wrapper.jar rename to 301 - Witch Jobsite/.mvn/wrapper/maven-wrapper.jar diff --git a/301/.mvn/wrapper/maven-wrapper.properties b/301 - Witch Jobsite/.mvn/wrapper/maven-wrapper.properties similarity index 100% rename from 301/.mvn/wrapper/maven-wrapper.properties rename to 301 - Witch Jobsite/.mvn/wrapper/maven-wrapper.properties diff --git a/301/mvnw b/301 - Witch Jobsite/mvnw similarity index 100% rename from 301/mvnw rename to 301 - Witch Jobsite/mvnw diff --git a/301/mvnw.cmd b/301 - Witch Jobsite/mvnw.cmd similarity index 100% rename from 301/mvnw.cmd rename to 301 - Witch Jobsite/mvnw.cmd diff --git a/301/pom.xml b/301 - Witch Jobsite/pom.xml similarity index 100% rename from 301/pom.xml rename to 301 - Witch Jobsite/pom.xml diff --git a/301/src/main/java/com/diegom40/flamencowitches/jobsite/JobsiteApplication.java b/301 - Witch Jobsite/src/main/java/com/diegom40/flamencowitches/jobsite/JobsiteApplication.java similarity index 100% rename from 301/src/main/java/com/diegom40/flamencowitches/jobsite/JobsiteApplication.java rename to 301 - Witch Jobsite/src/main/java/com/diegom40/flamencowitches/jobsite/JobsiteApplication.java diff --git a/301/src/main/java/com/diegom40/flamencowitches/jobsite/controller/PostController.java b/301 - Witch Jobsite/src/main/java/com/diegom40/flamencowitches/jobsite/controller/PostController.java similarity index 100% rename from 301/src/main/java/com/diegom40/flamencowitches/jobsite/controller/PostController.java rename to 301 - Witch Jobsite/src/main/java/com/diegom40/flamencowitches/jobsite/controller/PostController.java diff --git a/301/src/main/java/com/diegom40/flamencowitches/jobsite/model/Post.java b/301 - Witch Jobsite/src/main/java/com/diegom40/flamencowitches/jobsite/model/Post.java similarity index 100% rename from 301/src/main/java/com/diegom40/flamencowitches/jobsite/model/Post.java rename to 301 - Witch Jobsite/src/main/java/com/diegom40/flamencowitches/jobsite/model/Post.java diff --git a/301/src/main/java/com/diegom40/flamencowitches/jobsite/repository/PostRepository.java b/301 - Witch Jobsite/src/main/java/com/diegom40/flamencowitches/jobsite/repository/PostRepository.java similarity index 100% rename from 301/src/main/java/com/diegom40/flamencowitches/jobsite/repository/PostRepository.java rename to 301 - Witch Jobsite/src/main/java/com/diegom40/flamencowitches/jobsite/repository/PostRepository.java diff --git a/301/src/main/java/com/diegom40/flamencowitches/jobsite/repository/SearchRepository.java b/301 - Witch Jobsite/src/main/java/com/diegom40/flamencowitches/jobsite/repository/SearchRepository.java similarity index 100% rename from 301/src/main/java/com/diegom40/flamencowitches/jobsite/repository/SearchRepository.java rename to 301 - Witch Jobsite/src/main/java/com/diegom40/flamencowitches/jobsite/repository/SearchRepository.java diff --git a/301/src/main/java/com/diegom40/flamencowitches/jobsite/repository/SearchRepositoryImpl.java b/301 - Witch Jobsite/src/main/java/com/diegom40/flamencowitches/jobsite/repository/SearchRepositoryImpl.java similarity index 100% rename from 301/src/main/java/com/diegom40/flamencowitches/jobsite/repository/SearchRepositoryImpl.java rename to 301 - Witch Jobsite/src/main/java/com/diegom40/flamencowitches/jobsite/repository/SearchRepositoryImpl.java diff --git a/301/src/main/resources/application.properties b/301 - Witch Jobsite/src/main/resources/application.properties similarity index 100% rename from 301/src/main/resources/application.properties rename to 301 - Witch Jobsite/src/main/resources/application.properties diff --git a/301/src/test/java/com/diegom40/flamencowitches/jobsite/JobsiteApplicationTests.java b/301 - Witch Jobsite/src/test/java/com/diegom40/flamencowitches/jobsite/JobsiteApplicationTests.java similarity index 100% rename from 301/src/test/java/com/diegom40/flamencowitches/jobsite/JobsiteApplicationTests.java rename to 301 - Witch Jobsite/src/test/java/com/diegom40/flamencowitches/jobsite/JobsiteApplicationTests.java diff --git a/302 - Leetcode/0002 Add Two Numbers/AddTwoNumbers.java b/302 - Leetcode/0002 Add Two Numbers/AddTwoNumbers.java new file mode 100644 index 0000000..de28fa4 --- /dev/null +++ b/302 - Leetcode/0002 Add Two Numbers/AddTwoNumbers.java @@ -0,0 +1,39 @@ +/** + * 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 l1, ListNode l2) { + + ListNode prePreFirstResult = new ListNode(); + prePreFirstResult.next = new ListNode(); + ListNode result = prePreFirstResult.next; + int carry = 0; + // While a new node is necessary... + while (carry == 1 || l1 != null || l2 != null){ + if (l1 == null){ + l1 = new ListNode(0); + } + if (l2 == null){ + l2 = new ListNode(0); + } + ListNode nextResult = new ListNode ((l1.val + l2.val + carry)%10); + result.next = nextResult; + if (l1.val + l2.val + carry >= 10){ + carry = 1; + } else { + carry = 0; + } + l1 = l1.next; + l2 = l2.next; + result = nextResult; + } + return prePreFirstResult.next.next; + } +} \ No newline at end of file