leetcode) 383. ransom note

Doongsil·2024년 5월 10일

✅ 알파벳이 나온 횟수를 배열에 저장

func canConstruct(ransomNote string, magazine string) bool {
	var cnts [26]int
	for i := range magazine {
		cnts[magazine[i]-97]++
	}
	for i := range ransomNote {
		index := ransomNote[i]-97
		if cnts[index]==0 {
			return false
		}
		cnts[index]--
	}
	return true
}

📝 https://leetcode.com/problems/ransom-note/description/?envType=study-plan-v2&envId=top-interview-150

profile
두둥실

0개의 댓글