Skip to content

Commit 037bbee

Browse files
authored
Fixed idea warnings, added common ListNode class.
1 parent 810b719 commit 037bbee

File tree

33 files changed

+79
-217
lines changed

33 files changed

+79
-217
lines changed

SECURITY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@
1111

1212
In case you have found a vulnerability, please open a public issue in the repository. This will help developers to address the problem and solve.
1313

14-
If you have evidence of a zero day exploit, please directly contact to project owner with exploit details.
14+
If you have evidence of a zero-day exploit, please directly contact to project owner with exploit details.

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@
140140
<dependency>
141141
<groupId>junit</groupId>
142142
<artifactId>junit</artifactId>
143-
<version>4.13.1</version>
143+
<version>[4.13.2,)</version>
144144
<scope>test</scope>
145145
</dependency>
146146
</dependencies>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.github.leetcode;
2+
3+
@SuppressWarnings("java:S1104")
4+
public class ListNode {
5+
public int val;
6+
public ListNode next;
7+
8+
public ListNode() {}
9+
10+
public ListNode(int val) {
11+
this.val = val;
12+
}
13+
14+
public ListNode(int val, ListNode next) {
15+
this.val = val;
16+
this.next = next;
17+
}
18+
19+
public String toString() {
20+
StringBuilder result = new StringBuilder("" + val);
21+
if (next.next != null) {
22+
result.append(", ");
23+
}
24+
ListNode current = next;
25+
while (current.next != null) {
26+
result.append(current.val);
27+
if (current.next != null) {
28+
result.append(", ");
29+
}
30+
current = current.next;
31+
}
32+
result.append(current.val);
33+
return result.toString();
34+
}
35+
}

src/main/java/s0001.two.sum/Solution.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import java.util.Arrays;
44

5-
@SuppressWarnings("java:S1598")
65
public class Solution {
76
public int[] twoSum(int[] nums, int target) {
87
if (nums == null || nums.length <= 1) {

src/main/java/s0002.add.two.numbers/ListNode.java

Lines changed: 0 additions & 20 deletions
This file was deleted.

src/main/java/s0002.add.two.numbers/Solution.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package s0002.add.two.numbers;
22

3+
import com.github.leetcode.ListNode;
4+
35
/*
46
* Definition for singly-linked list.
57
* public class ListNode {

src/main/java/s0003.longest.substring.without.repeating.characters/Solution.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@
22

33
public class Solution {
44
public int lengthOfLongestSubstring(String s) {
5-
int lastIndices[] = new int[256];
5+
int[] lastIndices = new int[256];
66
for (int i = 0; i < 256; i++) {
77
lastIndices[i] = -1;
88
}
99

1010
int maxLen = 0;
1111
int curLen = 0;
1212
int start = 0;
13-
int bestStart = 0;
1413
for (int i = 0; i < s.length(); i++) {
1514
char cur = s.charAt(i);
1615
if (lastIndices[cur] < start) {
@@ -25,7 +24,6 @@ public int lengthOfLongestSubstring(String s) {
2524

2625
if (curLen > maxLen) {
2726
maxLen = curLen;
28-
bestStart = start;
2927
}
3028
}
3129

src/main/java/s0004.median.of.two.sorted.arrays/Solution.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66

77
public class Solution {
88
public double findMedianSortedArrays(int[] nums1, int[] nums2) {
9-
List<Integer> l = new ArrayList<Integer>();
9+
List<Integer> l = new ArrayList<>();
1010
double f;
11-
for (int i = 0; i < nums1.length; i++) l.add(nums1[i]);
12-
for (int j = 0; j < nums2.length; j++) l.add(nums2[j]);
11+
for (int j : nums1) l.add(j);
12+
for (int i : nums2) l.add(i);
1313
Collections.sort(l);
1414
int k = l.size();
1515
if (k % 2 == 0) f = (double) ((l.get(k / 2 - 1)) + (l.get(k / 2))) / 2;

src/main/java/s0006.zigzag.conversion/Solution.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
public class Solution {
44
public String convert(String s, int numRows) {
55
if (s == null || s.length() <= numRows || numRows == 1) return s;
6-
char letters[] = new char[s.length()];
6+
char[] letters = new char[s.length()];
77
for (int i = 0, k = 0; i < numRows; i++) {
88
if (i == 0 || i == numRows - 1) {
99
for (int j = i; j < s.length(); j += 2 * numRows - 2) {

src/main/java/s0010.regular.expression.matching/Solution.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
public class Solution {
44
public boolean isMatch(String s, String p) {
5-
Boolean dp[][] = new Boolean[s.length() + 1][p.length() + 1];
5+
Boolean[][] dp = new Boolean[s.length() + 1][p.length() + 1];
66
return isMatch(s, p, 0, 0, dp);
77
}
88

9-
public boolean isMatch(String s, String p, int i, int j, Boolean dp[][]) {
9+
public boolean isMatch(String s, String p, int i, int j, Boolean[][] dp) {
1010
if (i == s.length() && j == p.length()) {
1111
return true;
1212
}

0 commit comments

Comments
 (0)