From 9a19118119e26c7cdab20e548f7fab7d88fc5a53 Mon Sep 17 00:00:00 2001 From: Ilya Nikokoshev Date: Thu, 26 May 2022 01:56:08 +0200 Subject: [PATCH] Improve the SolutionShort --- lc_0354_envelopes.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lc_0354_envelopes.py b/lc_0354_envelopes.py index f0394f7..9d4ff36 100644 --- a/lc_0354_envelopes.py +++ b/lc_0354_envelopes.py @@ -1,14 +1,15 @@ from bisect import bisect_left +from math import inf from typing import List import unittest class SolutionShort: def maxEnvelopes(self, envelopes: List[List[int]]) -> int: - m = [float("inf")] * len(envelopes) + m = [inf] * (len(envelopes) + 1) for _, h in sorted(envelopes, key=lambda x: (x[0], -x[1])): m[bisect_left(m, h)] = h - return sum(v < float("inf") for v in m) + return m.index(inf) def set_val(a, v, i):