Programmers/프로그래머스-A 강조하기-Python/Go/Java

cosmos·2023년 7월 6일
0
post-thumbnail
post-custom-banner

문제

Python Code

def solution(myString: str) -> str:
    return ''.join(map(str, ['A' if x.lower() == 'a' else x.lower() for x in myString]))

Go Code

import (
    "strings"
    "unicode"
)

func solution(myString string) string {
	result := strings.Builder{}
	for _, char := range myString {
		if char == 'a' {
			result.WriteString("A")
		} else if unicode.IsUpper(char) && char != 'A' {
			result.WriteString(strings.ToLower(string(char)))
		} else {
			result.WriteString(string(char))
		}
	}
	return result.String()
}

Java Code

class Solution {
    public static String solution(String myString) {
        StringBuilder result = new StringBuilder();
        for (char c : myString.toCharArray()) {
            if (c == 'a') {
                result.append('A');
            } else if (Character.isUpperCase(c) && c != 'A') {
                result.append(Character.toLowerCase(c));
            } else {
                result.append(c);
            }
        }
        return result.toString();
    }
}

결과

문제 출처 & 깃허브

Programmers
Github

post-custom-banner

0개의 댓글