Playing Around on LeetCode

Enjoy the madness
class Solution(object):
def countMatches(self, items, ruleKey, ruleValue):
"""
:type items: List[List[str]]
:type ruleKey: str
:type ruleValue: str
:rtype: int
"""
match_rule_count = 0
rule_indexes = {
'type': 0,
'color': 1,
'name': 2
}
rule_index = rule_indexes[ruleKey]
for item in items:
if item[rule_index] == ruleValue:
match_rule_count += 1
return match_rule_count
class Solution(object):
def countMatches(self, i, k, v):
c, s = 0, {'type': 0,'color': 1,'name': 2}
a = s[k]
for j in i:
if j[a] == v:
c += 1
return c
Slower runtime, but better memory usage by .1
class Solution(object):
def countMatches(self, i, k, v):
c, s = 0, {'t': 0,'c': 1,'n': 2}
a = s[k[0]]
for j in i:
if j[a] == v:
c += 1
return c
class Solution(object):
def countMatches(self, i, k, v):
c = 0
for j in i:
if (k[0] == 't' and j[0] == v) or (k[0] == 'c' and j[1] == v) or (k[0] == 'n' and j[2] == v):
c += 1
return c
Maybe I got lucky with this run

--

--

--

I’ve learned more about PERL than I care to admit.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

10 must have productivity apps for Senior Government Officers

Brief introduction to Apache Kafka

E-Commerce Testing丨How to Test an eCommerce Website?

E-Commerce testing-how to test an e-commerce website?-51testing

Lesson 7 Background Tasks

Efficient Automation: How to get the most out of your workflows

Why is Xamarin a good choice?

Force-load Outlook Addin with Powershell

9 Fixes for Wdf01000.sys Blue Screen Error in Windows 10

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Daryan Hanshew

Daryan Hanshew

I’ve learned more about PERL than I care to admit.

More from Medium

LeetCode Patterns Adventure 27 — Lowest Common Ancestor of a Binary Search Tree

Box Stack Problem — Recursive way

Choosing Appropriate Data Structure

[Leetcode 525] Contiguous Array