擅长:python、mysql、java
<p>试试这个:</p>
<pre><code>else:
# Find the first element that matches
while mid > 0 and sortedSamples[mid - 1].attr == desired_attr:
mid -= 1
# Iterate until an element that doesn't match is found.
while mid < len(sortedSamples) and sortedSamples[mid].attr == desired_attr:
newList.append(sortedObjects[mid])
mid += 1
</code></pre>
<p>它在O(m)时间内运行,其中m是具有所需属性的对象数。在</p>