문제를 이해하고 있다면 바로 풀이를 보면 됨
전체 코드로 바로 넘어가도 됨
마음대로 번역해서 오역이 있을 수 있음
친구가 키보드에 자신의 이름을 입력하고 있다. 때때로 c와 같은 문자를 입력할 때 키가 길게 눌린 상태로 입력되어 한 번 이상 입력될 수 있다.
입력된 문자를 분석하여, 입력된 문자 중 일부(또는 전혀 없을 수도 있음)가 친구의 이름일 가능성이 있다면 true를 반환해라.
#1
Input: name = "alex", typed = "aaleex"
Output: true
Explanation: alex에 있는 a와 e는 길게 눌렸다.
#2
Input: name = "saeed", typed = "ssaaedd"
Output: false
Explanation: e가 두 번 입력해야 하는데 출력된 typed는 그렇지 않다.
class Solution {
public boolean isLongPressedName(String name, String typed) {
int i = 0;
int m = name.length();
int n = typed.length();
for(int j = 0; j < n; j++){
if(i < m && name.charAt(i) == typed.charAt(j)){
i++;
}else if(j == 0 || typed.charAt(j) != typed.charAt(j - 1)){
return false;
}
}
return i == m;
}
}