Skip to content

Instantly share code, notes, and snippets.

@modos
Created November 3, 2022 22:01
Show Gist options
  • Save modos/8db005d74cb0782ebf3e0eb1809db59b to your computer and use it in GitHub Desktop.
Save modos/8db005d74cb0782ebf3e0eb1809db59b to your computer and use it in GitHub Desktop.
سوال اول
// Online IDE - Code Editor, Compiler, Interpreter
public class RepeatInString {
public int StringInString(String one, String two) {
if (one == null || two == null) {
return 0;
}
int M = two.length();
int N = one.length();
int res = 0;
if (one == "" || two == "") {
return 0;
}
/* A loop to slide pat[] one by one */
for (int i = 0; i <= N - M; i++) {
/*
* For current index i, check for
* pattern match
*/
int j;
for (j = 0; j < M; j++) {
if (one.charAt(i + j) != two.charAt(j)) {
break;
}
}
// if pat[0...M-1] = txt[i, i+1, ...i+M-1]
if (j == M) {
res++;
j = 0;
}
}
return res;
}
// public static void main(String[] args) {
// System.out.println(StringInString("sasasas", "sas"));
// }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment