[leetcode, JS] 2309. Greatest English Letter in Upper and Lower Case

mxxn·2023년 10월 6일
0

leetcode

목록 보기
90/198

문제

문제 링크 : Greatest English Letter in Upper and Lower Case

풀이

/**
 * @param {string} s
 * @return {string}
 */
var greatestLetter = function(s) {
    let set=new Set(s.split(""));
	// ASCII(A-Z, a-z)=(65-90, 97-122).
    for(let i=90; i>=65; i--){
        if(set.has(String.fromCharCode(i)) && set.has(String.fromCharCode(i+32))){
            return String.fromCharCode(i);
        }
    }
    return "";
};
  1. 문자열 s를 split하고 중복제거한 후
  2. lower와 upper가 동시에 존재하는 알파벳 찾아서 return
  • Runtime 55 ms, Memory 44 MB
profile
내일도 글쓰기

0개의 댓글