01-23 07:25
Recent Posts
Recent Comments
๊ด€๋ฆฌ ๋ฉ”๋‰ด

miinsun

[Programmers] JadenCase ๋ฌธ์ž์—ด ๋งŒ๋“ค๊ธฐ - JAVA (๋ฌธ์ž์—ด ์ฒ˜๋ฆฌ) ๋ณธ๋ฌธ

Algorithm/Programmers

[Programmers] JadenCase ๋ฌธ์ž์—ด ๋งŒ๋“ค๊ธฐ - JAVA (๋ฌธ์ž์—ด ์ฒ˜๋ฆฌ)

miinsun 2022. 5. 19. 00:21

 

๐Ÿ’ฌ ๋ฌธ์ œ ์„ค๋ช…

JadenCase๋ž€ ๋ชจ๋“  ๋‹จ์–ด์˜ ์ฒซ ๋ฌธ์ž๊ฐ€ ๋Œ€๋ฌธ์ž์ด๊ณ , ๊ทธ ์™ธ์˜ ์•ŒํŒŒ๋ฒณ์€ ์†Œ๋ฌธ์ž์ธ ๋ฌธ์ž์—ด์ž…๋‹ˆ๋‹ค.
๋‹จ, ์ฒซ ๋ฌธ์ž๊ฐ€ ์•ŒํŒŒ๋ฒณ์ด ์•„๋‹ ๋•Œ์—๋Š” ์ด์–ด์ง€๋Š” ์•ŒํŒŒ๋ฒณ์€ ์†Œ๋ฌธ์ž๋กœ ์“ฐ๋ฉด ๋ฉ๋‹ˆ๋‹ค. (์ฒซ ๋ฒˆ์งธ ์ž…์ถœ๋ ฅ ์˜ˆ ์ฐธ๊ณ )

๋ฌธ์ž์—ด s๊ฐ€ ์ฃผ์–ด์กŒ์„ ๋•Œ, s๋ฅผ JadenCase๋กœ ๋ฐ”๊พผ ๋ฌธ์ž์—ด์„ ๋ฆฌํ„ดํ•˜๋Š” ํ•จ์ˆ˜, solution์„ ์™„์„ฑํ•ด์ฃผ์„ธ์š”.

 

๐Ÿšซ ์ œํ•œ ์‚ฌํ•ญ

  • s๋Š” ๊ธธ์ด 1 ์ด์ƒ 200 ์ดํ•˜์ธ ๋ฌธ์ž์—ด์ž…๋‹ˆ๋‹ค.
  • s๋Š” ์•ŒํŒŒ๋ฒณ๊ณผ ์ˆซ์ž, ๊ณต๋ฐฑ๋ฌธ์ž(" ")๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ์Šต๋‹ˆ๋‹ค.
    • ์ˆซ์ž๋Š” ๋‹จ์–ด์˜ ์ฒซ ๋ฌธ์ž๋กœ๋งŒ ๋‚˜์˜ต๋‹ˆ๋‹ค.
    • ์ˆซ์ž๋กœ๋งŒ ์ด๋ฃจ์–ด์ง„ ๋‹จ์–ด๋Š” ์—†์Šต๋‹ˆ๋‹ค.
    • ๊ณต๋ฐฑ๋ฌธ์ž๊ฐ€ ์—ฐ์†ํ•ด์„œ ๋‚˜์˜ฌ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

๐Ÿ”จ ์ž…์ถœ๋ ฅ ์˜ˆ

โ€‹

๐Ÿ’ป Solution.java

  • ๋จผ์ € ๋ฌธ์ž์—ด์„ ๋ชจ๋‘ ์†Œ๋ฌธ์ž๋กœ ๋ฐ”๊พผ๋‹ค.
  • flag ๋ณ€์ˆ˜ isBlank๋ฅผ ์ด์šฉํ•ด ๋นˆ์นธ์ด ์˜ค๋ฉด, ๊ทธ ๋‹ค์Œ ๋ฌธ์ž๋Š” ๋Œ€๋ฌธ์ž๋กœ ๋ฐ”๊ฟ”์ค€๋‹ค.
  • ์ผ๋ฐ˜ ๋ฌธ์ž ๋‹ค์Œ ๋ฌธ์ž๋Š” ๊ทธ๋ƒฅ answer์— ๋”ํ•ด์ค€๋‹ค.
public class Solution {
  public String solution(String s) {
        String answer = "";
        char[] arr = s.toLowerCase().toCharArray();
        
        boolean isBlank = true;
        for(int i = 0; i < arr.length; i++) {
        	if(arr[i] == ' ') {
    			answer += arr[i];
        		isBlank = true;
        	}
        	else {
        		if(isBlank) {
        			answer += Character.toUpperCase(arr[i]);
        			isBlank = false;
        		}
        		else {
        			answer += arr[i];
        		}
        	}

        }
        
        return answer;
    }
}

 

Comments