We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see ourdocumentation.
There was an error while loading.Please reload this page.
1 parentca5b470 commit9f40349Copy full SHA for 9f40349
src/main/java/com/fishercoder/solutions/_128.java
@@ -116,7 +116,8 @@ public int longestConsecutive(int[] nums) {
116
}
117
118
intlongestStreak =0;
119
-for (intnum :set) {//we'll go through this set instead of nums, this makes a big difference in time complexity, esp. based on LeetCode test cases
+for (intnum :set) {
120
+//we'll go through this set instead of nums, this makes a big difference in time complexity, esp. based on LeetCode test cases
121
if (!set.contains(num -1)) {
122
intcurrentNum =num;
123
intcurrentStreak =1;
src/main/java/com/fishercoder/solutions/_148.java
@@ -63,8 +63,9 @@ public static class Solution2 {
63
ListNodenextSubList =newListNode(0);
64
65
publicListNodesortList(ListNodehead) {
66
-if (head ==null ||head.next ==null)
+if (head ==null ||head.next ==null) {
67
returnhead;
68
+ }
69
intn =getCount(head);
70
ListNodestart =head;
71
ListNodedummyHead =newListNode(0);
src/main/java/com/fishercoder/solutions/_1650.java
@@ -17,7 +17,8 @@ public Node(int val) {
17
18
publicstaticclassSolution1 {
19
publicNodelowestCommonAncestor(Nodep,Nodeq) {
20
-Nodea =p,b =q;
+Nodea =p;
21
+Nodeb =q;
22
while (a !=b) {
23
a =a ==null ?p :a.parent;
24
b =b ==null ?q :b.parent;
src/main/java/com/fishercoder/solutions/_1721.java
@@ -69,6 +69,7 @@ public ListNode swapNodes(ListNode head, int k) {
returndummy.next;
72
+
73
publicstaticclassSolution3 {
74
publicListNodeswapNodes(ListNodehead,intk) {
75
// O(n) linear time
@@ -80,20 +81,21 @@ public ListNode swapNodes(ListNode head, int k) {
80
81
intlength =0;
82
intsecondIndex;
83
-ListNodetemp1 =null,temp2 =null;
84
+ListNodetemp1 =null;
85
+ListNodetemp2 =null;
86
ListNodetemp3 =head;
-while(temp3 !=null){
87
+while(temp3 !=null){
88
length++;
89
temp3 =temp3.next;
90
91
92
secondIndex =length -k +1;
93
temp3 =head;
-for(inti =1;i <=length;i++){
-if(i ==k){
94
+for(inti =1;i <=length;i++){
95
+if(i ==k){
96
temp1 =temp3;
97
-if(i ==secondIndex){
98
+if(i ==secondIndex){
99
temp2 =temp3;
100
101
src/main/java/com/fishercoder/solutions/_1826.java
@@ -4,7 +4,8 @@ public class _1826 {
4
5
publicintbadSensor(int[]sensor1,int[]sensor2) {
6
//check if sensor2 is faulty
7
-inti =0,j =0;
+inti =0;
8
+intj =0;
9
for (;i <sensor1.length &&j <sensor2.length -1; ) {
10
if (sensor1[i] !=sensor2[j]) {
11
i++;
src/main/java/com/fishercoder/solutions/_2001.java
@@ -35,7 +35,7 @@ public static class Solution2 {
35
*/
36
publiclonginterchangeableRectangles(int[][]rectangles) {
37
Map<Double,Integer>map =newHashMap<>();
38
-longans =0l;
+longans =0L;
39
for (int[]rec :rectangles) {
40
doubleratio = (double)rec[0] /rec[1];
41
ans +=map.getOrDefault(ratio,0);
src/main/java/com/fishercoder/solutions/_2028.java
@@ -3,7 +3,7 @@
3
publicclass_2028 {
publicint[]missingRolls(int[]rolls,intmean,intn) {
-longsum =0l;
+longsum =0L;
for (intnum :rolls) {
sum +=num;
src/main/java/com/fishercoder/solutions/_264.java
@@ -41,7 +41,7 @@ public static class Solution2 {
42
publicintnthUglyNumber(intn) {
43
TreeSet<Long>treeSet =newTreeSet<>();
44
-treeSet.add(1l);
+treeSet.add(1L);
45
intcount =1;
46
intpolled =0;
47
int[]primes =newint[]{2,3,5};
src/main/java/com/fishercoder/solutions/_380.java
@@ -37,7 +37,8 @@ public boolean remove(int val) {
returnfalse;
}else {
intremoveIndex =map.get(val);
-if (removeIndex !=list.size() -1) {//if it's not the last element, then we need to swap it with the last element so that this operation is also O(1)
+if (removeIndex !=list.size() -1) {
+//if it's not the last element, then we need to swap it with the last element so that this operation is also O(1)
intlastElement =list.get(list.size() -1);
list.set(removeIndex,lastElement);
map.put(lastElement,removeIndex);
src/main/java/com/fishercoder/solutions/_698.java
@@ -49,7 +49,7 @@ public static class Solution2 {
49
50
publicbooleancanPartitionKSubsets(int[]nums,intk) {
51
Arrays.sort(nums);
52
53
for (intnum :nums) {
54
55