Search
Duplicate
๐Ÿ“•

Word Pattern

์ฃผ์ฐจ
๋ฌธ์ œ๋ฒˆํ˜ธ
290
์–ธ์–ด
Swift
ํ‹ฐ์–ด
Easy
์œ ํ˜•
๋ฌธ์ž์—ด
ํ•ด์‹œ๋ฅผ ์‚ฌ์šฉํ•œ ์ง‘ํ•ฉ๊ณผ ๋งต
nj_Blog
nj_์ƒํƒœ
์ดํ•ด๋„
33%
ํ’€์ด
์‚ฌ๋žŒ
์ดํ•ด๋„ 2
13 more properties

๋ฌธ์ œ์ ‘๊ทผ

โ€ข
hashtable ๊ตฌ์„ฑ

๋†“์ณค๋˜ ๋ถ€๋ถ„

โ€ข
zip ๋ฉ”์„œ๋“œ
โ€ข
default ์˜ต์…˜

์ฝ”๋“œ

14.3 MB

0 ms

class Solution { func wordPattern(_ pattern: String, _ str: String) -> Bool { var dicChar = [Character : String]() var dicWord = [String : Character]() let words = str.split(separator: " ") if words.count != pattern.count { return false } for (char, word) in zip(pattern, words) { let w = "\(word)" if dicChar[char, default: w] != w { return false } dicChar[char] = w if dicWord[w, default: char] != char { return false } dicWord[w] = char } return true } }
Swift
๋ณต์‚ฌ