Skip to content

Commit d1a1547

Browse files
add 1570
1 parent d83c7e0 commit d1a1547

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ _If you like this project, please leave me a star._ ★
3636
|1576|[Replace All ?'s to Avoid Consecutive Repeating Characters](https://leetcode.com/problems/replace-all-s-to-avoid-consecutive-repeating-characters/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1576.java) |[:tv:](https://youtu.be/SJBDLYqrIsM)|Easy|String|
3737
|1574|[Shortest Subarray to be Removed to Make Array Sorted](https://leetcode.com/problems/shortest-subarray-to-be-removed-to-make-array-sorted/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1574.java) ||Medium|Array, Binary Search|
3838
|1572|[Matrix Diagonal Sum](https://leetcode.com/problems/matrix-diagonal-sum/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1572.java) ||Easy|Array|
39+
|1570|[Dot Product of Two Sparse Vectors](https://leetcode.com/problems/dot-product-of-two-sparse-vectors/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1570.java) ||Easy|Array, HashTable, Two Pointers|
3940
|1567|[Maximum Length of Subarray With Positive Product](https://leetcode.com/problems/maximum-length-of-subarray-with-positive-product/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1567.java) |[:tv:](https://youtu.be/bFer5PdsgpY)|Medium|Greedy|
4041
|1566|[Detect Pattern of Length M Repeated K or More Times](https://leetcode.com/problems/detect-pattern-of-length-m-repeated-k-or-more-times/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1566.java) |[:tv:](https://youtu.be/aJAV_VgmjdE)|Easy|Array|
4142
|1561|[Maximum Number of Coins You Can Get](https://leetcode.com/problems/maximum-number-of-coins-you-can-get/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1561.java) |[:tv:](https://youtu.be/hPe9Z3TiUrA)|Medium|Sort|
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.fishercoder.solutions;
2+
3+
public class _1570 {
4+
public static class Solution1 {
5+
class SparseVector {
6+
int[] vector;
7+
8+
SparseVector(int[] nums) {
9+
this.vector = nums;
10+
}
11+
12+
// Return the dotProduct of two sparse vectors
13+
public int dotProduct(SparseVector vec) {
14+
int[] incoming = vec.vector;
15+
int dotProduct = 0;
16+
for (int i = 0; i < vector.length; i++) {
17+
dotProduct += incoming[i] * this.vector[i];
18+
}
19+
return dotProduct;
20+
}
21+
}
22+
}
23+
}

0 commit comments

Comments
 (0)