inblog logo
|
stupefyee
    알고리즘문제풀기

    [JAVA 문제 풀이] 354. Find the Original Typed String I [원본 타이핑 문자열 I 찾기]

    리트코드
    Stupefyee's avatar
    Stupefyee
    Jul 01, 2025
    [JAVA 문제 풀이] 354. Find the Original Typed String I [원본 타이핑 문자열 I 찾기]
    Contents
    내가 작성한 코드
    Find the Original Typed String I - LeetCode
    Can you solve this real interview question? Find the Original Typed String I - Alice is attempting to type a specific string on her computer. However, she tends to be clumsy and may press a key for too long, resulting in a character being typed multiple times. Although Alice tried to focus on her typing, she is aware that she may still have done this at most once. You are given a string word, which represents the final output displayed on Alice's screen. Return the total number of possible original strings that Alice might have intended to type.   Example 1: Input: word = "abbcccc" Output: 5 Explanation: The possible strings are: "abbcccc", "abbccc", "abbcc", "abbc", and "abcccc". Example 2: Input: word = "abcd" Output: 1 Explanation: The only possible string is "abcd". Example 3: Input: word = "aaaa" Output: 4   Constraints: * 1 <= word.length <= 100 * word consists only of lowercase English letters.
    Find the Original Typed String I - LeetCode
    https://leetcode.com/problems/find-the-original-typed-string-i/description/
    Find the Original Typed String I - LeetCode
    notion image
    notion image
    앨리스는 컴퓨터에 특정 문자열을 입력하려고 시도하고 있습니다. 하지만 그녀는 서투른 경향이 있고 키를 너무 오래 눌러 문자를 여러 번 입력할 수 있습니다. 앨리스는 타이핑에 집중하려고 했지만, 그래도 한 번쯤은 했을지도 모른다는 것을 알고 있습니다. 앨리스 화면에 표시되는 최종 출력을 나타내는 문자열 단어가 주어집니다. 앨리스가 입력하려고 했을 가능성이 있는 원본 문자열의 총 개수를 반환합니다. 제약 조건: 1 <= 단어.길이 <= 100 단어는 소문자로만 구성됩니다.
     

    내가 작성한 코드

    public class Solution { public int possibleStringCount(String word) { int ans = 1; // 처음에는 무조건 1개는 있음 for (int i = 1; i < word.length(); i++) { if (word.charAt(i) == word.charAt(i - 1)) { // 지금 문자열이랑 다음 문자열이 같으면 ans++; // 가능한 문자열의 개수 증가 } } return ans; } }
    Share article
    Contents
    내가 작성한 코드

    stupefyee

    RSS·Powered by Inblog