Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: doocs/leetcode
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 06052c459d620b5a7fd22a5edfc010c8f41e50cf
Choose a base ref
..
head repository: doocs/leetcode
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 999a4231d84ba17bc59b03bda219a6b5bb70d90e
Choose a head ref
Showing with 564 additions and 100 deletions.
  1. +34 −0 lcci/02.02.Kth Node From End of List/README.md
  2. +34 −0 lcci/02.02.Kth Node From End of List/README_EN.md
  3. +31 −0 lcci/02.02.Kth Node From End of List/Solution.swift
  4. +20 −0 lcci/02.03.Delete Middle Node/README.md
  5. +20 −0 lcci/02.03.Delete Middle Node/README_EN.md
  6. +17 −0 lcci/02.03.Delete Middle Node/Solution.swift
  7. +38 −0 lcci/02.04.Partition List/README.md
  8. +38 −0 lcci/02.04.Partition List/README_EN.md
  9. +35 −0 lcci/02.04.Partition List/Solution.swift
  10. +4 −4 lcci/16.15.Master Mind/README.md
  11. +4 −4 lcci/16.15.Master Mind/README_EN.md
  12. +4 −4 lcci/16.15.Master Mind/Solution.js
  13. +9 −9 solution/1800-1899/1856.Maximum Subarray Min-Product/README.md
  14. +9 −9 solution/1800-1899/1856.Maximum Subarray Min-Product/README_EN.md
  15. +9 −9 solution/1800-1899/1856.Maximum Subarray Min-Product/Solution.ts
  16. +18 −24 solution/1800-1899/1883.Minimum Skips to Arrive at Meeting On Time/README.md
  17. +33 −25 solution/1800-1899/1883.Minimum Skips to Arrive at Meeting On Time/README_EN.md
  18. +71 −4 solution/3100-3199/3119.Maximum Number of Potholes That Can Be Fixed/README.md
  19. +71 −4 solution/3100-3199/3119.Maximum Number of Potholes That Can Be Fixed/README_EN.md
  20. +1 −1 solution/3100-3199/3119.Maximum Number of Potholes That Can Be Fixed/Solution.cpp
  21. +24 −0 solution/3100-3199/3119.Maximum Number of Potholes That Can Be Fixed/Solution.cs
  22. +1 −1 solution/3100-3199/3119.Maximum Number of Potholes That Can Be Fixed/Solution.go
  23. +1 −1 solution/3100-3199/3119.Maximum Number of Potholes That Can Be Fixed/Solution.java
  24. +4 −0 solution/3100-3199/3119.Maximum Number of Potholes That Can Be Fixed/Solution.py
  25. +33 −0 solution/3100-3199/3119.Maximum Number of Potholes That Can Be Fixed/Solution.rs
  26. +1 −1 solution/3100-3199/3119.Maximum Number of Potholes That Can Be Fixed/Solution.ts
34 changes: 34 additions & 0 deletions lcci/02.02.Kth Node From End of List/README.md
Original file line number Diff line number Diff line change
@@ -203,6 +203,40 @@ var kthToLast = function (head, k) {
};
```

```swift
/**
* Definition for singly-linked list.
* public class ListNode {
* var val: Int
* var next: ListNode?
* init(_ x: Int, _ next: ListNode? = nil) {
* self.val = x
* self.next = next
* }
* }
*/

class Solution {
func kthToLast(_ head: ListNode?, _ k: Int) -> Int {
var slow = head
var fast = head
var k = k

while k > 0 {
fast = fast?.next
k -= 1
}

while fast != nil {
slow = slow?.next
fast = fast?.next
}

return slow?.val ?? 0
}
}
```

<!-- tabs:end -->

<!-- end -->
34 changes: 34 additions & 0 deletions lcci/02.02.Kth Node From End of List/README_EN.md
Original file line number Diff line number Diff line change
@@ -205,6 +205,40 @@ var kthToLast = function (head, k) {
};
```

```swift
/**
* Definition for singly-linked list.
* public class ListNode {
* var val: Int
* var next: ListNode?
* init(_ x: Int, _ next: ListNode? = nil) {
* self.val = x
* self.next = next
* }
* }
*/

class Solution {
func kthToLast(_ head: ListNode?, _ k: Int) -> Int {
var slow = head
var fast = head
var k = k

while k > 0 {
fast = fast?.next
k -= 1
}

while fast != nil {
slow = slow?.next
fast = fast?.next
}

return slow?.val ?? 0
}
}
```

<!-- tabs:end -->

<!-- end -->
31 changes: 31 additions & 0 deletions lcci/02.02.Kth Node From End of List/Solution.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* Definition for singly-linked list.
* public class ListNode {
* var val: Int
* var next: ListNode?
* init(_ x: Int, _ next: ListNode? = nil) {
* self.val = x
* self.next = next
* }
* }
*/

class Solution {
func kthToLast(_ head: ListNode?, _ k: Int) -> Int {
var slow = head
var fast = head
var k = k

while k > 0 {
fast = fast?.next
k -= 1
}

while fast != nil {
slow = slow?.next
fast = fast?.next
}

return slow?.val ?? 0
}
}
20 changes: 20 additions & 0 deletions lcci/02.03.Delete Middle Node/README.md
Original file line number Diff line number Diff line change
@@ -114,6 +114,26 @@ var deleteNode = function (node) {
};
```

```swift
/**
* public class ListNode {
* var val: Int
* var next: ListNode?
* init(_ x: Int) {
* self.val = x
* self.next = nil
* }
* }
*/
class Solution {
func deleteNode(_ node: ListNode?) {
guard let node = node, let next = node.next else { return }
node.val = next.val
node.next = next.next
}
}
```

<!-- tabs:end -->

<!-- end -->
20 changes: 20 additions & 0 deletions lcci/02.03.Delete Middle Node/README_EN.md
Original file line number Diff line number Diff line change
@@ -109,6 +109,26 @@ var deleteNode = function (node) {
};
```

```swift
/**
* public class ListNode {
* var val: Int
* var next: ListNode?
* init(_ x: Int) {
* self.val = x
* self.next = nil
* }
* }
*/
class Solution {
func deleteNode(_ node: ListNode?) {
guard let node = node, let next = node.next else { return }
node.val = next.val
node.next = next.next
}
}
```

<!-- tabs:end -->

<!-- end -->
17 changes: 17 additions & 0 deletions lcci/02.03.Delete Middle Node/Solution.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* public class ListNode {
* var val: Int
* var next: ListNode?
* init(_ x: Int) {
* self.val = x
* self.next = nil
* }
* }
*/
class Solution {
func deleteNode(_ node: ListNode?) {
guard let node = node, let next = node.next else { return }
node.val = next.val
node.next = next.next
}
}
38 changes: 38 additions & 0 deletions lcci/02.04.Partition List/README.md
Original file line number Diff line number Diff line change
@@ -201,6 +201,44 @@ function partition(head: ListNode | null, x: number): ListNode | null {
}
```

```swift
/** public class ListNode {
* var val: Int
* var next: ListNode?
* init(_ x: Int) {
* self.val = x
* self.next = nil
* }
* }
*/

class Solution {
func partition(_ head: ListNode?, _ x: Int) -> ListNode? {
let leftDummy = ListNode(0)
let rightDummy = ListNode(0)
var left = leftDummy
var right = rightDummy
var head = head

while let current = head {
if current.val < x {
left.next = current
left = left.next!
} else {
right.next = current
right = right.next!
}
head = head?.next
}

right.next = nil
left.next = rightDummy.next

return leftDummy.next
}
}
```

<!-- tabs:end -->

<!-- end -->
38 changes: 38 additions & 0 deletions lcci/02.04.Partition List/README_EN.md
Original file line number Diff line number Diff line change
@@ -179,6 +179,44 @@ function partition(head: ListNode | null, x: number): ListNode | null {
}
```

```swift
/** public class ListNode {
* var val: Int
* var next: ListNode?
* init(_ x: Int) {
* self.val = x
* self.next = nil
* }
* }
*/

class Solution {
func partition(_ head: ListNode?, _ x: Int) -> ListNode? {
let leftDummy = ListNode(0)
let rightDummy = ListNode(0)
var left = leftDummy
var right = rightDummy
var head = head

while let current = head {
if current.val < x {
left.next = current
left = left.next!
} else {
right.next = current
right = right.next!
}
head = head?.next
}

right.next = nil
left.next = rightDummy.next

return leftDummy.next
}
}
```

<!-- tabs:end -->

<!-- end -->
35 changes: 35 additions & 0 deletions lcci/02.04.Partition List/Solution.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/** public class ListNode {
* var val: Int
* var next: ListNode?
* init(_ x: Int) {
* self.val = x
* self.next = nil
* }
* }
*/

class Solution {
func partition(_ head: ListNode?, _ x: Int) -> ListNode? {
let leftDummy = ListNode(0)
let rightDummy = ListNode(0)
var left = leftDummy
var right = rightDummy
var head = head

while let current = head {
if current.val < x {
left.next = current
left = left.next!
} else {
right.next = current
right = right.next!
}
head = head?.next
}

right.next = nil
left.next = rightDummy.next

return leftDummy.next
}
}
8 changes: 4 additions & 4 deletions lcci/16.15.Master Mind/README.md
Original file line number Diff line number Diff line change
@@ -108,16 +108,16 @@ var masterMind = function (solution, guess) {
let counts2 = { R: 0, G: 0, B: 0, Y: 0 };
let res1 = 0;
for (let i = 0; i < solution.length; i++) {
let s1 = solution.charAt(i),
s2 = guess.charAt(i);
if (s1 == s2) {
let s1 = solution[i],
s2 = guess[i];
if (s1 === s2) {
res1++;
} else {
counts1[s1] += 1;
counts2[s2] += 1;
}
}
let res2 = ['R', 'G', 'B', 'Y'].reduce((a, c) => a + Math.min(counts1[c], counts2[c]), 0);
let res2 = Object.keys(counts1).reduce((a, c) => a + Math.min(counts1[c], counts2[c]), 0);
return [res1, res2];
};
```
8 changes: 4 additions & 4 deletions lcci/16.15.Master Mind/README_EN.md
Original file line number Diff line number Diff line change
@@ -115,16 +115,16 @@ var masterMind = function (solution, guess) {
let counts2 = { R: 0, G: 0, B: 0, Y: 0 };
let res1 = 0;
for (let i = 0; i < solution.length; i++) {
let s1 = solution.charAt(i),
s2 = guess.charAt(i);
if (s1 == s2) {
let s1 = solution[i],
s2 = guess[i];
if (s1 === s2) {
res1++;
} else {
counts1[s1] += 1;
counts2[s2] += 1;
}
}
let res2 = ['R', 'G', 'B', 'Y'].reduce((a, c) => a + Math.min(counts1[c], counts2[c]), 0);
let res2 = Object.keys(counts1).reduce((a, c) => a + Math.min(counts1[c], counts2[c]), 0);
return [res1, res2];
};
```
8 changes: 4 additions & 4 deletions lcci/16.15.Master Mind/Solution.js
Original file line number Diff line number Diff line change
@@ -8,15 +8,15 @@ var masterMind = function (solution, guess) {
let counts2 = { R: 0, G: 0, B: 0, Y: 0 };
let res1 = 0;
for (let i = 0; i < solution.length; i++) {
let s1 = solution.charAt(i),
s2 = guess.charAt(i);
if (s1 == s2) {
let s1 = solution[i],
s2 = guess[i];
if (s1 === s2) {
res1++;
} else {
counts1[s1] += 1;
counts2[s2] += 1;
}
}
let res2 = ['R', 'G', 'B', 'Y'].reduce((a, c) => a + Math.min(counts1[c], counts2[c]), 0);
let res2 = Object.keys(counts1).reduce((a, c) => a + Math.min(counts1[c], counts2[c]), 0);
return [res1, res2];
};
Loading