Skip to content

Commit

Permalink
adding leetcode folder
Browse files Browse the repository at this point in the history
  • Loading branch information
abhishektripathi66 committed Jul 29, 2022
1 parent b959816 commit 0cf8065
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
43 changes: 43 additions & 0 deletions Leetcode/findandreplace.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package Leetcode;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class findandreplace {

public static void main(String[] args) {
findandreplace far = new findandreplace();
String arr[] = {"abc","deq","mee","aqq","dkd","ccc"};
List<String> op = far.findAndReplacePattern(arr, "abb");
System.out.println(op);
}

public List<String> findAndReplacePattern(String[] words, String pattern) {

List<String> res = new ArrayList<String>();

for(String str: words){
if(match(str, pattern)){
res.add(str);
}
}
return res;
}

public Boolean match(String str, String pattern){

HashMap<Character, Character> hm = new HashMap<>();
for(int i = 0; i < str.length(); i++){
if(!hm.containsKey(pattern.charAt(i))){
if(hm.containsValue(str.charAt(i))){
return false;
}
hm.put(pattern.charAt(i), str.charAt(i));
} else if(hm.get(pattern.charAt(i)) != str.charAt(i)){
return false;
}
}
return true;
}
}
Binary file added arrayproject/averagetemp.class
Binary file not shown.
28 changes: 28 additions & 0 deletions arrayproject/averagetemp.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package arrayproject;

import java.util.Scanner;

public class averagetemp {

public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("How many Days temperature?");
int numberOfDays = scanner.nextInt();
int[] temp = new int[numberOfDays];
int average =0;
int sum=0;
System.out.println("Enter the temparature of that many days");
for(int i=0;i<numberOfDays;i++){
temp[i]=scanner.nextInt();
sum+=temp[i];
}

average = sum/numberOfDays;

System.out.println("The average temparature is "+average);
for(int i=0;i<numberOfDays;i++){
if(temp[i]>average) System.out.println("Day "+(i+1)+"'s temperature is above average");
}

}
}

0 comments on commit 0cf8065

Please sign in to comment.