강의

멘토링

로드맵

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

dayeong님의 프로필 이미지
dayeong

작성한 질문수

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

3. 문장 속 단어(indexOf(), substring())

이런 방식도 괜찮을까요?

작성

·

245

1

이런 방식도 괜찮을까요?

public String solution(String str){

String answer = "";

for(String s : str.split(" ")){
if(s.length() > answer.length()) answer = s;
}

return answer;
}

퀴즈

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

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

안녕하세요^^

네. 좋은 코드입니다.

dayeong님의 프로필 이미지
dayeong

작성한 질문수

질문하기