Contents

A ๊ฐ•์กฐํ•˜๊ธฐ(with.Java)

   Oct 14, 2023     1 min read

A ๊ฐ•์กฐํ•˜๊ธฐ์— ๋Œ€ํ•˜์—ฌ ์•Œ์•„๋ณธ ๊ธ€์ž…๋‹ˆ๋‹ค.

์ฝ”๋”ฉ ํ…Œ์ŠคํŠธ ๋ฌธ์ œ๋ฅผ ํ’€๋ฉฐ, ํ’€์—ˆ๋˜ ๋ฌธ์ œ์— ๋Œ€ํ•œ ํšŒ๊ณ ์™€ ๋‹ค๋ฅธ ํ’€์ด ๋ฐฉ๋ฒ•์„ ์•Œ์•„๋ณด๋ฉฐ, ์•Œ์•„๊ฐ€๊ณ ์ž ํ•ฉ๋‹ˆ๋‹ค.

๋ฌธ์ œ์— ๋Œ€ํ•ด ๋จผ์ € ์•Œ์•„๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

๋ฌธ์ œ

๋ฌธ์ž์—ด myString์ด ์ฃผ์–ด์ง‘๋‹ˆ๋‹ค.

myString์—์„œ ์•ŒํŒŒ๋ฒณ โ€œaโ€๊ฐ€ ๋“ฑ์žฅํ•˜๋ฉด ์ „๋ถ€ โ€œAโ€๋กœ ๋ณ€ํ™˜ํ•˜๊ณ , โ€œAโ€๊ฐ€ ์•„๋‹Œ ๋ชจ๋“  ๋Œ€๋ฌธ์ž ์•ŒํŒŒ๋ฒณ์€ ์†Œ๋ฌธ์ž ์•ŒํŒŒ๋ฒณ์œผ๋กœ ๋ณ€ํ™˜ํ•˜์—ฌ return ํ•˜๋Š” solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•˜์„ธ์š”.

์ž…์ถœ๋ ฅ ์˜ˆ์‹œ
myStringresult
โ€œabstract algebraโ€โ€œAbstrAct AlgebrAโ€

๋ฌธ์ œ์— ๋Œ€ํ•œ ๋‚˜์˜ ํ’€์ด

class Solution {
    public String solution(String myString) {
        StringBuilder result = new StringBuilder();
        for (int i = 0; i < myString.length(); i++) {
            char currentChar = myString.charAt(i);
            if (currentChar == 'a') {
                result.append('A');
            }else if(currentChar == 'A'){
                result.append(currentChar);
            }else if (Character.isUpperCase(currentChar)) {
                result.append(Character.toLowerCase(currentChar));
            }else {
                result.append(currentChar);
            }
        }
        return result.toString();
    }
}
ํ’€์ด ์„ค๋ช…

์œ„ ์ฝ”๋“œ๋Š” ์ฃผ์–ด์ง„ ๋ฌธ์ž์—ด์„ ํ•œ ๊ธ€์ž์”ฉ ์ˆœํšŒํ•˜๋ฉฐ ์กฐ๊ฑด์„ ํ™•์ธํ•˜์—ฌ ๋ฌธ์ž์—ด์„ ๋ณ€ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

๋ฌธ์ž๊ฐ€ โ€˜Aโ€™์ผ ๊ฒฝ์šฐ์—๋Š” ๊ทธ๋Œ€๋กœ ์œ ์ง€ํ•˜๊ณ , ๋Œ€๋ฌธ์ž ์•ŒํŒŒ๋ฒณ์ผ ๊ฒฝ์šฐ์—๋Š” ์†Œ๋ฌธ์ž๋กœ ๋ณ€ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

๊ทธ ์™ธ์˜ ๋ฌธ์ž๋Š” ๊ทธ๋Œ€๋กœ ์œ ์ง€๋ฉ๋‹ˆ๋‹ค.

๋ฌธ์ž์—ด ์—ฐ์‚ฐ ์„ฑ๋Šฅ์„ ๊ณ ๋ คํ•˜์—ฌ StringBuilder๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ฌธ์ž์—ด์„ ๊ตฌ์„ฑํ•˜๋„๋ก ๊ตฌํ˜„๋˜์—ˆ์Šต๋‹ˆ๋‹ค.