String 5

2024 11 04 3163. String Compression III

문제Given a string word, compress it using the following algorithm:Begin with an empty string comp. While word is not empty, use the following operation:Remove a maximum length prefix of word made of a single character c repeating at most 9 times.Append the length of the prefix followed by c to comp.Return the string comp.요약연속된 문자가 몇개있는지 세되 9개 씩만풀이어렵진않다 우선 첫글자를 저장해두고 다음 문자가 같은지 비교후 다르거나 9를 넘는다면 sb..

알고리즘 2024.11.04

2024 11 03 Result796. Rotate String

문제Given two strings s and goal, return true if and only if s can become goal after some number of shifts on s.A shift on s consists of moving the leftmost character of s to the rightmost position.For example, if s = "abcde", then it will be "bcdea" after one shift.요약첫글자를 마지막으로 돌리면서 goal과 같은게 나오는지 검사풀이처음에는 String.substring으로 풀긴했는데 효율이 너무 안좋게 나오길레그냥 s 문자 안바꾸고 idx로 검하였다.코드class Solution { public..

알고리즘 2024.11.03

2024 11 04 1957. Delete Characters to Make Fancy String

문제A fancy string is a string where no three consecutive characters are equal.Given a string s, delete the minimum possible number of characters from s to make it fancy.Return the final string after the deletion. It can be shown that the answer will always be unique.요약String에서 연속으로 같은 char 3개가 나오지않게 제거풀이char를 하나씩 조회하면서 counting 하며 3개 이상이 되면 무시, 다른 글자가 나올 경우 count를 초기화하고 진행코드class Solution { pu..

알고리즘 2024.11.01