---
# System prepended metadata

title: leeCode Practice

---

### 敘述統計
```python=
class Solution:
    def sampleStats(self, count: List[int]) -> List[float]:
        minVal = next(i for i in range(256) if count[i] > 0)
        maxVal = next(i for i in range(255, -1, -1) if count[i] > 0)
        meanVal = sum(i * count[i] for i in range(256)) / sum(count)
        modeVal = count.index(max(count))
        
        totalCount = sum(count)
        halfCount = totalCount // 2
        
        if totalCount % 2 == 0:
            countSum = 0
            first = None
            second = None
            for i, c in enumerate(count):
                countSum += c
                if countSum >= halfCount and first is None:
                    first = i
                if countSum >= halfCount + 1:
                    second = i
                    break
            medianVal = (first + second) / 2
        else:
            countSum = 0
            for i, c in enumerate(count):
                countSum += c
                if countSum > halfCount:
                    medianVal = i
                    break
        
        return [float(minVal), float(maxVal), meanVal, medianVal, float(modeVal)]

```