Skip to content

Commit f8bdede

Browse files
committed
Data analysis by practical
1 parent 49d7ca6 commit f8bdede

File tree

6 files changed

+1525
-9
lines changed

6 files changed

+1525
-9
lines changed
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 2,
6+
"metadata": {},
7+
"outputs": [
8+
{
9+
"name": "stdout",
10+
"output_type": "stream",
11+
"text": [
12+
"[1, 3, 6, 10]\n"
13+
]
14+
}
15+
],
16+
"source": [
17+
"# # input \n",
18+
"# nums = [1,2,3,4]\n",
19+
"# # ouput \n",
20+
"# # nums = [1, 3, 6, 10]\n",
21+
"# # Declare a variable where you can store the sum\n",
22+
"# sum = 0 \n",
23+
"# #Declare a list where you will append the sum o\n",
24+
"# result = []\n",
25+
"# for i in nums:\n",
26+
"# sum += i\n",
27+
"# result.append(sum)\n",
28+
"\n",
29+
"# print(result)"
30+
]
31+
},
32+
{
33+
"cell_type": "code",
34+
"execution_count": 7,
35+
"metadata": {},
36+
"outputs": [],
37+
"source": [
38+
"# Time: O(n^2)\n",
39+
"# Space: O(1)\n",
40+
"\n",
41+
"class Solution(object):\n",
42+
" def threeSumClosest(self, nums, target):\n",
43+
" \"\"\"\n",
44+
" :type nums: List[int]\n",
45+
" :type target: int\n",
46+
" :rtype: int\n",
47+
" \"\"\"\n",
48+
" result, min_diff = 0, float(\"inf\")\n",
49+
" nums.sort()\n",
50+
" for i in reversed(xrange(2, len(nums))):\n",
51+
" if i+1 < len(nums) and nums[i] == nums[i+1]:\n",
52+
" continue\n",
53+
" left, right = 0, i-1\n",
54+
" while left < right:\n",
55+
" total = nums[left]+nums[right]+nums[i]\n",
56+
" if total < target:\n",
57+
" left += 1\n",
58+
" elif total > target:\n",
59+
" right -= 1\n",
60+
" else:\n",
61+
" return target\n",
62+
" if abs(total-target) < min_diff:\n",
63+
" min_diff = abs(total-target)\n",
64+
" result = total\n",
65+
" return result\n",
66+
"\n"
67+
]
68+
}
69+
],
70+
"metadata": {
71+
"kernelspec": {
72+
"display_name": "Python 3.10.7 64-bit",
73+
"language": "python",
74+
"name": "python3"
75+
},
76+
"language_info": {
77+
"codemirror_mode": {
78+
"name": "ipython",
79+
"version": 3
80+
},
81+
"file_extension": ".py",
82+
"mimetype": "text/x-python",
83+
"name": "python",
84+
"nbconvert_exporter": "python",
85+
"pygments_lexer": "ipython3",
86+
"version": "3.10.7"
87+
},
88+
"orig_nbformat": 4,
89+
"vscode": {
90+
"interpreter": {
91+
"hash": "26de051ba29f2982a8de78e945f0abaf191376122a1563185a90213a26c5da77"
92+
}
93+
}
94+
},
95+
"nbformat": 4,
96+
"nbformat_minor": 2
97+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"cells": [],
3+
"metadata": {},
4+
"nbformat": 4,
5+
"nbformat_minor": 5
6+
}

0 commit comments

Comments
 (0)