Skip to content

Commit 591fc3d

Browse files
committed
Prepare for publication
1 parent 94dab56 commit 591fc3d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+27
-432
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@
1414
.~lock*
1515
*.kate-swp
1616
**/Migrate*.java
17+
**/RenameMethodParms.java

src/main/java/io/github/spannm/leetcode/LeetcodeProblem.java

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,9 @@
22

33
public abstract class LeetcodeProblem {
44

5-
private final boolean doOutput;
6-
7-
protected LeetcodeProblem() {
8-
this(true);
9-
}
10-
11-
protected LeetcodeProblem(boolean _doOutput) {
12-
doOutput = _doOutput;
13-
}
14-
15-
public final boolean doOutput() {
16-
return doOutput;
17-
}
18-
19-
public final void printf(String _format, Object... _args) {
20-
if (doOutput) {
21-
System.out.printf(_format, _args);
22-
}
23-
}
24-
25-
public final void println(Object _arg) {
26-
if (doOutput) {
27-
System.out.println(_arg);
28-
}
29-
}
30-
315
@Override
326
public String toString() {
33-
return getClass().getSimpleName() + "[]";
7+
return String.format("%s[]", getClass().getSimpleName());
348
}
359

3610
public static String asString(Object _o) {

src/main/java/io/github/spannm/leetcode/LeetcodeSqlProblem.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ public abstract class LeetcodeSqlProblem extends LeetcodeProblem {
55
private final String sql;
66

77
protected LeetcodeSqlProblem(String _sql) {
8-
super(true);
98
sql = _sql;
109
}
1110

src/main/java/io/github/spannm/leetcode/dep/Sudoku.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,7 @@ public boolean solve(Board _board) {
3737

3838
List<Field> fields = _board.boxes.stream().flatMap(b -> b.getFields().stream()).toList();
3939

40-
// inspect field by field
41-
for (Field currFld : fields) {
42-
// if (currFld.getRowNo() == 'A' && currFld.getColNo() == 1) {
43-
// doOutput(" DEBUG ");
44-
// }
45-
// doOutput(" %s%n", currFld);
40+
for (Field currFld : fields) { // inspect field by field
4641

4742
// check all remaining possible values whether one is only possible in this field
4843
for (Area area : currFld.getAreas()) {

src/main/java/io/github/spannm/leetcode/lc0/lc0000/Problem0001.java

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,23 @@
22

33
import io.github.spannm.leetcode.LeetcodeProblem;
44

5+
import java.util.ArrayList;
6+
import java.util.List;
7+
58
/**
69
* <a href="https://leetcode.com/problems/two-sum/">1. Two Sum</a>.
710
*/
811
class Problem0001 extends LeetcodeProblem {
912

1013
int[] twoSum(int[] _nums, int _target) {
11-
if (doOutput()) {
12-
printf("Input: %s, target: %d%n", java.util.Arrays.toString(_nums), _target);
13-
}
14-
return impl1(_nums, _target);
15-
}
16-
17-
int[] impl1(int[] _nums, int _target) {
18-
final java.util.List<IdxAndNum> idxAndNums = new java.util.ArrayList<>();
14+
List<IdxAndNum> idxAndNums = new ArrayList<>();
1915
for (int i = 0; i < _nums.length; i++) {
2016
idxAndNums.add(new IdxAndNum(i, _nums[i]));
2117
}
2218
idxAndNums.sort(java.util.Comparator.comparing(IdxAndNum::getNum).thenComparing(IdxAndNum::getIdx));
2319

2420
final int len = idxAndNums.size();
2521

26-
if (doOutput()) {
27-
printf("Values (%s): %s%n", len, idxAndNums);
28-
}
29-
3022
int[] result = null;
3123

3224
for (int i1 = 0; i1 < len - 1; i1++) {
@@ -40,19 +32,14 @@ int[] impl1(int[] _nums, int _target) {
4032

4133
}
4234

43-
System.err.printf("No result found! %n%n");
4435
return null;
4536
}
4637

4738
/**
4839
* Calculates the sum of two values.<br>
4940
* If equal to {@code target}, returns their indices in an int array.
5041
*/
51-
int[] calcSum(IdxAndNum _in1, IdxAndNum _in2, int _target) {
52-
if (doOutput()) {
53-
printf(" Test %s + %s = %s %n%n", _in1, _in2, _target);
54-
}
55-
42+
static int[] calcSum(IdxAndNum _in1, IdxAndNum _in2, int _target) {
5643
if (_in1.getNum() + _in2.getNum() == _target) {
5744
return new int[] {_in1.getIdx(), _in2.getIdx()};
5845
}

src/main/java/io/github/spannm/leetcode/lc0/lc0000/Problem0004.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,18 @@
1313
class Problem0004 extends LeetcodeProblem {
1414

1515
double findMedianSortedArrays(int[] _nums1, int[] _nums2) {
16-
final LinkedList<Integer> l1 = Arrays.stream(_nums1).boxed().collect(Collectors.toCollection(LinkedList::new));
17-
final LinkedList<Integer> l2 = Arrays.stream(_nums2).boxed().collect(Collectors.toCollection(LinkedList::new));
16+
LinkedList<Integer> l1 = Arrays.stream(_nums1).boxed().collect(Collectors.toCollection(LinkedList::new));
17+
LinkedList<Integer> l2 = Arrays.stream(_nums2).boxed().collect(Collectors.toCollection(LinkedList::new));
1818

1919
// merge sorted arrays into one
2020
final LinkedList<Integer> merged = new LinkedList<>();
21-
// Solange noch nicht beide Listen hinzugefügt worden
2221
while (!l1.isEmpty() && !l2.isEmpty()) {
2322
if (l1.getFirst() <= l2.getFirst()) {
2423
merged.addLast(l1.removeFirst());
2524
} else {
2625
merged.addLast(l2.removeFirst());
2726
}
2827
}
29-
// Füge Rest hinzu, falls etwas übrig ist.
3028
merged.addAll(l1);
3129
merged.addAll(l2);
3230

@@ -46,15 +44,9 @@ List<Integer> merge(LinkedList<Integer> _l1, LinkedList<Integer> _l2) {
4644
merged.addLast(_l2.removeFirst());
4745
}
4846
}
49-
// Füge Rest hinzu, falls etwas übrig ist.
5047
merged.addAll(_l1);
5148
merged.addAll(_l2);
5249
return merged;
5350
}
5451

55-
public void printFindMedianSortedArrays(int[] _nums1, int[] _nums2) {
56-
double result = findMedianSortedArrays(_nums1, _nums2);
57-
printf("%s and %s => %s%n", asString(_nums1), asString(_nums2), result);
58-
}
59-
6052
}

src/main/java/io/github/spannm/leetcode/lc0/lc0000/Problem0006.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ String convert(String _s, int _numRows) {
2323

2424
for (int i = 0; i < arr.length; i++) {
2525
sbs.get(z).append(arr[i]);
26-
printf("i=%s, z=%s, v=%s %s %n", i, z, arr[i], up ? "up" : "down");
2726
if (up) {
2827
z++;
2928
} else {
@@ -34,10 +33,6 @@ String convert(String _s, int _numRows) {
3433
}
3534
}
3635

37-
if (doOutput()) {
38-
sbs.forEach(this::println);
39-
}
40-
4136
return sbs.stream().map(StringBuilder::toString).collect(Collectors.joining(""));
4237
}
4338

src/main/java/io/github/spannm/leetcode/lc0/lc0000/Problem0008.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
class Problem0008 extends LeetcodeProblem {
66

77
int myAtoi(String _s) {
8-
printf("Input: %s %n", _s);
98
if (_s == null || _s.isEmpty()) {
109
return 0;
1110
}

src/main/java/io/github/spannm/leetcode/lc0/lc0000/Problem0017.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ public List<String> letterCombinations2(String _digits) {
6868
Set<String> combinations = new LinkedHashSet<>();
6969

7070
generatePermutations(lol, combinations, 0, "");
71-
printf("Combinations: %s %n", combinations);
7271

7372
return new ArrayList<>(combinations);
7473
}

src/main/java/io/github/spannm/leetcode/lc0/lc0000/Problem0019.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
class Problem0019 extends LeetcodeProblem {
1010

1111
ListNode removeNthFromEnd(ListNode _head, int _n) {
12-
printf("Input: %s, n=%d%n", _head, _n);
1312
ListNode node = _head;
1413

1514
int count = 1;
@@ -25,7 +24,6 @@ ListNode removeNthFromEnd(ListNode _head, int _n) {
2524
}
2625

2726
int position = count - _n + 1; // position to remove
28-
printf("Position of node to remove: %d (%d from end)%n", position, _n);
2927
if (position == 1) {
3028
_head = _head.next;
3129
return _head;

0 commit comments

Comments
 (0)