Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 227f64d

Browse files
newProblems
1 parent 2af784f commit 227f64d

23 files changed

+1523
-25
lines changed

‎src/LeetcodeQuestions/TopKFreqElement.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package LeetcodeQuestions;
22

3-
import java.util.*;
3+
import java.util.Comparator;
4+
import java.util.HashMap;
5+
import java.util.Map;
6+
import java.util.PriorityQueue;
47

58

69
class Pair implements Comparable<Pair> {

‎src/LeetcodeQuestions/TwoSum.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package LeetcodeQuestions;
22

3-
import java.util.*;
3+
import java.util.HashMap;
4+
import java.util.Map;
45
public class TwoSum {
56

67

‎src/LeetcodeQuestions/uniquePath.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package LeetcodeQuestions;
22

3-
import recursion.quicksort;
4-
53
// https://leetcode.com/problems/unique-paths/
64
// https://leetcode.com/problems/unique-paths-ii/
75
public class uniquePath {

‎src/Prep/BestPlayerFan.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package Prep;
22

3-
import java.util.*;
3+
import java.util.Arrays;
4+
import java.util.Scanner;
45

56
// https://www.hackerearth.com/practice/algorithms/sorting/bubble-sort/practice-problems/algorithm/the-best-player-1/editorial/
67

‎src/arrays/tripletsum.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package arrays;
22

3-
import java.util.Scanner;
43
import java.util.Arrays;
4+
import java.util.Scanner;
55

66
public class tripletsum {
77

‎src/graphs/color.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package graphs;
22

3-
import java.util.*;
3+
import java.util.Scanner;
44

55
public class color {
66

‎src/graphs/prims.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package graphs;
22

3-
import java.util.Arrays;
43
import java.util.Scanner;
54

65

‎src/hashmaps/test.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33

44
import java.util.HashMap;
5+
import java.util.Map.Entry;
56
import java.util.Set;
6-
import java.util.Map.Entry;;
7+
8+
;
79

810

911
public class test {

‎src/revision/kconcat.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
package revision;
33

4-
import java.util.*;
4+
import java.util.Scanner;
55

66
class Codechef {
77

‎src/strings/KMPSearch.java

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package strings;
2+
3+
public class KMPSearch
4+
{
5+
6+
public static boolean search(String str,String pat){
7+
8+
int n=str.length();
9+
int m=pat.length();
10+
11+
int lps[]=new int[m];
12+
13+
computeLPS(pat,m,lps);
14+
15+
int i=0,j=0;
16+
17+
while(i<n){
18+
19+
if(str.charAt(i)==pat.charAt(j)){
20+
21+
i++;
22+
j++;
23+
24+
}
25+
if(j==m){
26+
return true;
27+
}
28+
else if(i<n && str.charAt(i)!=pat.charAt(j)){
29+
30+
if(j!=0){
31+
j=lps[j-1];
32+
}
33+
else{
34+
i++;
35+
}
36+
37+
}
38+
39+
40+
41+
}
42+
43+
return false;
44+
45+
46+
}
47+
48+
public static void computeLPS(String pat,int m,int[] lps){
49+
50+
int i=1,j=0;
51+
lps[0]=0;
52+
while(i<m){
53+
54+
if(pat.charAt(i)==pat.charAt(j)){
55+
j++;
56+
lps[i]=j;
57+
i++;
58+
}
59+
else{
60+
if(j!=0){
61+
j=lps[j-1];
62+
}
63+
else{
64+
lps[i]=j;
65+
i++;
66+
}
67+
}
68+
69+
70+
}
71+
72+
}
73+
74+
75+
76+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /