Skip to content

Commit bc33f85

Browse files
committed
long loops solution plus a one liner implementation
1 parent 0217f13 commit bc33f85

File tree

1 file changed

+136
-0
lines changed

1 file changed

+136
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
{
2+
"nbformat": 4,
3+
"nbformat_minor": 0,
4+
"metadata": {
5+
"colab": {
6+
"name": "Remove_duplicatesfromsortedlist_Leetcode.ipynb",
7+
"provenance": [],
8+
"authorship_tag": "ABX9TyN4dtnjmZDsqLDeTVn+BSKf",
9+
"include_colab_link": true
10+
},
11+
"kernelspec": {
12+
"name": "python3",
13+
"display_name": "Python 3"
14+
},
15+
"language_info": {
16+
"name": "python"
17+
}
18+
},
19+
"cells": [
20+
{
21+
"cell_type": "markdown",
22+
"metadata": {
23+
"id": "view-in-github",
24+
"colab_type": "text"
25+
},
26+
"source": [
27+
"<a href=\"https://colab.research.google.com/github/DebjitHore/Python-Codes/blob/master/Remove_duplicatesfromsortedlist_Leetcode.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
28+
]
29+
},
30+
{
31+
"cell_type": "code",
32+
"metadata": {
33+
"id": "DD1PcC7Fja6S"
34+
},
35+
"source": [
36+
"def remove_duplicates(nums):\n",
37+
" mylist=[]\n",
38+
" for i in range(0, len(nums)-1):\n",
39+
" for j in range(i+1, len(nums)):\n",
40+
" if nums[i]== nums[j] and j not in mylist:\n",
41+
" mylist.append(j)\n",
42+
" #mylist=np.unique(mylist)\n",
43+
" print(mylist)\n",
44+
" k=0\n",
45+
" for i in mylist:\n",
46+
" nums.pop(i-k)\n",
47+
" k+=1\n",
48+
" return (nums)"
49+
],
50+
"execution_count": 28,
51+
"outputs": []
52+
},
53+
{
54+
"cell_type": "code",
55+
"metadata": {
56+
"colab": {
57+
"base_uri": "https://localhost:8080/"
58+
},
59+
"id": "eS6uQbWcjucZ",
60+
"outputId": "6981fa71-c277-4053-8d48-596822ab422f"
61+
},
62+
"source": [
63+
"nums= [1,1,2]\n",
64+
"remov_duplicates(nums)"
65+
],
66+
"execution_count": 36,
67+
"outputs": [
68+
{
69+
"output_type": "execute_result",
70+
"data": {
71+
"text/plain": [
72+
"(2, [1, 2])"
73+
]
74+
},
75+
"metadata": {
76+
"tags": []
77+
},
78+
"execution_count": 36
79+
}
80+
]
81+
},
82+
{
83+
"cell_type": "code",
84+
"metadata": {
85+
"id": "xUueA04FlUbH"
86+
},
87+
"source": [
88+
"def remov_duplicates(nums):\n",
89+
" nums= list(set(nums))\n",
90+
" return (len(nums), nums)"
91+
],
92+
"execution_count": 33,
93+
"outputs": []
94+
},
95+
{
96+
"cell_type": "code",
97+
"metadata": {
98+
"colab": {
99+
"base_uri": "https://localhost:8080/"
100+
},
101+
"id": "GAyQlrIwpNwR",
102+
"outputId": "68adcd0a-8714-402a-8773-cf52a04ae22c"
103+
},
104+
"source": [
105+
"nums[:] = sorted(list(set(nums)))\n",
106+
"nums"
107+
],
108+
"execution_count": 38,
109+
"outputs": [
110+
{
111+
"output_type": "execute_result",
112+
"data": {
113+
"text/plain": [
114+
"[1, 2]"
115+
]
116+
},
117+
"metadata": {
118+
"tags": []
119+
},
120+
"execution_count": 38
121+
}
122+
]
123+
},
124+
{
125+
"cell_type": "code",
126+
"metadata": {
127+
"id": "HZDmHjGsprFs"
128+
},
129+
"source": [
130+
""
131+
],
132+
"execution_count": null,
133+
"outputs": []
134+
}
135+
]
136+
}

0 commit comments

Comments
 (0)