인프런 커뮤니티 질문&답변
<특정문자 뒤집기>함수 질문
작성
·
317
0
while(lt<rt){
if(!Character.isAlphabetic(s[lt])lt++;
else if(!Character.isAlphabetic(s([rt])rt--;
else{
char tmp=s[lt];
s[lt]=s[rt];
s[rt]=tmp;
lt++;
rt--;
}
}
안녕하세요 강사님
특정문자 뒤집기 문제에서 핵심 함수가 이해가 되지않아 질문드립니다.
제가 궁금한 점은 while문을 돌때 lt값과 rt값이 동시에 검증되는 것인지 아니면 while문 1번에 값이 하나만 검증되는 것인지 궁금합니다.
입력 값이 a#b!GE*T@S 일때 lt<rt이기때문에 lt는 알파벳이 아니기 때문에 1증가해서 두번째를 가리킵니다.
이 때 if문을 수행했기 때문에 while문을 빠져나오는 것 아닌가요? 3개중 하나를 만족하면 나오는 걸로 알고 있습니다.
아니면 그 다음 else if 문을 실행하여 rt값을 검증하고 1감소시키고 else문까지 끝까지 검증하고 while문 검증이 완료되는 것인지 궁금합니다.
답변 부탁드리겠습니다. 감사합니다.
퀴즈
What is the most efficient way to count the total number of specific characters in a string, ignoring case?
Iterate through the string and compare each character to both the uppercase and lowercase of the target character.
Convert the entire string to a single case (e.g., all uppercase) and count the characters.
Count uppercase and lowercase letters respectively and sum them.
Using a Set data structure, store characters without duplicates and then count them.





