- Published on
Count Items Matching a Rule
- Authors
- Name
- ShoxruxC
- @iOSdasturchi
📝 Vazifa tavsifi
Sizga items nomli massiv berilgan, bunda har bir items[i] = [typei, colori, namei] mos ravishda elementning turi, rangi va nomini ifodalaydi. Shuningdek, ikkita satr ruleKey va ruleValue berilgan.
Agar quyidagilardan biri to'g'ri bo'lsa, i-chi element qoidaga mos keladi deb hisoblanadi:
ruleKey == "type"varuleValue == typeiruleKey == "color"varuleValue == coloriruleKey == "name"varuleValue == namei
Qoidaga mos keladigan elementlar sonini qaytaring.
Misol:
Input: items = [["phone","blue","pixel"],["computer","silver","lenovo"],["phone","gold","iphone"]], ruleKey = "color", ruleValue = "silver"
Output: 1
Tushuntirish: Faqat bitta element mos keladi: ["computer","silver","lenovo"].
Count Items Matching a Rule
Oson10 daqiqa10 ball
📚 Misollar
Kiruvchi: items = [["phone","blue","pixel"],["computer","silver","lenovo"],["phone","gold","iphone"]], ruleKey = "color", ruleValue = "silver"
Chiquvchi: 1
func solve(_ items: [[String]], _ ruleKey: String, _ ruleValue: String) -> Int {
// Kodingizni shu yerga yozing
return 0
}
Run tugmasini bosing