-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b959816
commit 0cf8065
Showing
3 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
|
||
} | ||
} |