강의

멘토링

로드맵

인프런 커뮤니티 질문&답변

onil4115님의 프로필 이미지
onil4115

작성한 질문수

자바(Java) 알고리즘 문제풀이 입문: 코딩테스트 대비

5. 특정 문자 뒤집기(toCharArray())

<특정문자 뒤집기>함수 질문

작성

·

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.

답변 1

0

김태원님의 프로필 이미지
김태원
지식공유자

안녕하세요^^

if 문을 수행하면 while 문을 빠져나온다는게 무슨 말인지 이해가 가지 않습니다.

onil4115님의 프로필 이미지
onil4115

작성한 질문수

질문하기