문제
Python Code
def solution(myString: str, pat: str) -> int:
result = 0
for x in range(len(myString) - len(pat) + 1):
if myString[x:x+len(pat)] == pat:
result += 1
return result
Go Code
func solution(myString string, pat string) int {
count := 0
for i := 0; i <= len(myString)-len(pat); i++ {
if myString[i:i+len(pat)] == pat {
count++
}
}
return count
}
Java Code
class Solution {
public int solution(String myString, String pat) {
int count = 0;
for (int i = 0; i <= myString.length() - pat.length(); i++) {
if (myString.substring(i, i + pat.length()).equals(pat)) {
count++;
}
}
return count;
}
}
결과
문제출처 & 깃허브
Programmers
Github