Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions Problem42.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Time Complexity : O(n)
// Space Complexity : O(n)
// Did this code successfully run on Leetcode : Yes
// Any problem you faced while coding this : No


// Your code here along with comments explaining your approach

class Solution {
public int findPairs(int[] nums, int k) {
Map<Integer, Integer> map = new HashMap<Integer, Integer>();
int n = nums.length;
int count = 0;

for (int i = 0; i < n; i++) {
map.put(nums[i], map.getOrDefault(nums[i],0)+1);
}

for (int num : map.keySet()) {
if (k > 0) {
if (map.containsKey(num - k)) {
count++;
}
} else if (k == 0) {
if (map.get(num) > 1) {
count++;
}
}
}

return count;
}
}
27 changes: 27 additions & 0 deletions Problem43.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Time Complexity : O(n^2)
// Space Complexity : O(1)
// Did this code successfully run on Leetcode : Yes
// Any problem you faced while coding this : No


// Your code here along with comments explaining your approach
class Solution {
public List<List<Integer>> generate(int numRows) {

List<List<Integer>> result = new ArrayList<>();
result.add(Arrays.asList(1));

for(int i = 1; i < numRows; i++) {
List<Integer> prevRow = result.get(i - 1);
List<Integer> curRow = new ArrayList<>();
curRow.add(1);
for(int j = 1; j < prevRow.size(); j++) {
curRow.add(prevRow.get(j - 1) + prevRow.get(j));
}
curRow.add(1);
result.add(curRow);
}

return result;
}
}
7 changes: 0 additions & 7 deletions Sample.java

This file was deleted.