-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Rolf
committed
Sep 4, 2018
1 parent
24786ae
commit 441c849
Showing
3 changed files
with
37 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package tudelft.partition.exercise.caesarshift; | ||
package tudelft.caesarshift; | ||
|
||
public class CaesarShiftCipher { | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package tudelft.sum; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
|
||
// Source: https://leetcode.com/problems/add-two-numbers/description/ | ||
class TwoNumbersSum { | ||
|
||
public ArrayList<Integer> addTwoNumbers(ArrayList<Integer> first, ArrayList<Integer> second) { | ||
Collections.reverse(first); | ||
Collections.reverse(second); | ||
|
||
int complement = 0; | ||
ArrayList<Integer> result = new ArrayList<>(); | ||
|
||
for(int i = 0; i < Math.max(first.size(), second.size()); i++){ | ||
int firstVal = i < first.size() ? first.get(i) : 0; | ||
int secondVal = i < second.size() ? second.get(i) : 0; | ||
int total = firstVal + secondVal + complement; | ||
complement = 0; | ||
if (total >= 10){ | ||
complement = 1; | ||
total -= 10; | ||
} | ||
result.add(i, total); | ||
} | ||
|
||
Collections.reverse(result); | ||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package tudelft.sum; | ||
|
||
public class TwoNumbersSumTest { | ||
|
||
} |