{ "cells": [ { "cell_type": "code", "execution_count": null, "id": "32e3594e", "metadata": {}, "outputs": [ { "ename": "IndexError", "evalue": "list index out of range", "output_type": "error", "traceback": [ "\u001b[31m---------------------------------------------------------------------------\u001b[39m", "\u001b[31mIndexError\u001b[39m Traceback (most recent call last)", "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[9]\u001b[39m\u001b[32m, line 6\u001b[39m\n\u001b[32m 2\u001b[39m \n\u001b[32m 3\u001b[39m count = []\n\u001b[32m 4\u001b[39m \n\u001b[32m 5\u001b[39m \u001b[38;5;28;01mfor\u001b[39;00m num \u001b[38;5;28;01min\u001b[39;00m nums:\n\u001b[32m----> \u001b[39m\u001b[32m6\u001b[39m count[num] += \u001b[32m1\u001b[39m\n\u001b[32m 7\u001b[39m \n\u001b[32m 8\u001b[39m \u001b[38;5;66;03m# 2. Делаем префиксную сумму\u001b[39;00m\n\u001b[32m 9\u001b[39m \u001b[38;5;28;01mfor\u001b[39;00m i \u001b[38;5;28;01min\u001b[39;00m range(\u001b[32m1\u001b[39m, \u001b[32m101\u001b[39m):\n", "\u001b[31mIndexError\u001b[39m: list index out of range" ] } ], "source": [ "nums = [8,1,2,2,3,123,43,5,3,1,5,8,3,965,8,546,456,34,12,3]\n", "\n", "count = []\n", "\n", "for num in nums:\n", " if num in count:\n", " \n", " count[num] += 1\n", " \n", "for i in range(1, 101):\n", " count[i] += count[i-1]\n", "\n", "result = []\n", "for num in nums:\n", " if num == 0:\n", " result.append(0)\n", " else:\n", " result.append(count[num - 1])\n", "\n", "\n", "\n", "print(result)" ] } ], "metadata": { "kernelspec": { "display_name": "LeetCode_tasks", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.14.2" } }, "nbformat": 4, "nbformat_minor": 5 }