Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

done #938

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

done #938

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
29 changes: 29 additions & 0 deletions pairs-k-diff.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
class Solution {
public int findPairs(int[] nums, int k) {
HashMap<Integer,Integer> map = new HashMap<>();
int count=0;
for(int i=0;i<nums.length;i++){
map.put(nums[i],map.getOrDefault(nums[i],0)+1);
}

for(int key:map.keySet()){
if(k==0){
if(map.get(key)>1){
count++;
}
}
else {
if(map.containsKey(key+k) && map.get(key+k)!=-1){
count++;
map.put(key,-1);
}
if(map.containsKey(key-k) && map.get(key-k)!=-1){
count++;
map.put(key,-1);
}
}

}
return count;
}
}
26 changes: 26 additions & 0 deletions pascaltriangle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
class Solution {
public List<List<Integer>> generate(int numRows) {
List<List<Integer>> res = new ArrayList<>();
if(numRows==0) return res;
List<Integer> l1 = new ArrayList<>(Arrays.asList(1));
List<Integer> l2 = new ArrayList<>(Arrays.asList(1,1));
res.add(l1);
if(numRows==1){
return res;
}
res.add(l2);
if(numRows==2) return res;

for(int i=2;i<numRows;i++){
List li = new ArrayList<>();
li.add(1);
for(int j=1;j<i;j++){
int sol = res.get(i-1).get(j-1)+res.get(i-1).get(j);
li.add(sol);
}
li.add(1);
res.add(li);
}
return res;
}
}