Skip to content

Commit e92c842

Browse files
committed
DP easy
1 parent e78cbb2 commit e92c842

File tree

1 file changed

+171
-44
lines changed

1 file changed

+171
-44
lines changed

17. Dynamic Programming/00. LeetCode Easy.ipynb

Lines changed: 171 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"cells": [
33
{
44
"cell_type": "code",
5-
"execution_count": 1,
5+
"execution_count": null,
66
"metadata": {},
77
"outputs": [],
88
"source": [
@@ -18,7 +18,7 @@
1818
},
1919
{
2020
"cell_type": "code",
21-
"execution_count": 7,
21+
"execution_count": null,
2222
"metadata": {},
2323
"outputs": [],
2424
"source": [
@@ -36,20 +36,9 @@
3636
},
3737
{
3838
"cell_type": "code",
39-
"execution_count": 8,
39+
"execution_count": null,
4040
"metadata": {},
41-
"outputs": [
42-
{
43-
"data": {
44-
"text/plain": [
45-
"6"
46-
]
47-
},
48-
"execution_count": 8,
49-
"metadata": {},
50-
"output_type": "execute_result"
51-
}
52-
],
41+
"outputs": [],
5342
"source": [
5443
"cost = [10,15,20]\n",
5544
"cost = [1,100,1,1,1,100,1,1,100,1]\n",
@@ -65,7 +54,7 @@
6554
},
6655
{
6756
"cell_type": "code",
68-
"execution_count": 88,
57+
"execution_count": null,
6958
"metadata": {},
7059
"outputs": [],
7160
"source": [
@@ -79,20 +68,9 @@
7968
},
8069
{
8170
"cell_type": "code",
82-
"execution_count": 90,
71+
"execution_count": null,
8372
"metadata": {},
84-
"outputs": [
85-
{
86-
"data": {
87-
"text/plain": [
88-
"[1, 5, 10, 10, 5, 1]"
89-
]
90-
},
91-
"execution_count": 90,
92-
"metadata": {},
93-
"output_type": "execute_result"
94-
}
95-
],
73+
"outputs": [],
9674
"source": [
9775
"rowIndex = 5\n",
9876
"Solution().getRow(rowIndex)"
@@ -107,7 +85,7 @@
10785
},
10886
{
10987
"cell_type": "code",
110-
"execution_count": 103,
88+
"execution_count": null,
11189
"metadata": {},
11290
"outputs": [],
11391
"source": [
@@ -125,7 +103,7 @@
125103
},
126104
{
127105
"cell_type": "code",
128-
"execution_count": 109,
106+
"execution_count": null,
129107
"metadata": {},
130108
"outputs": [],
131109
"source": [
@@ -140,25 +118,174 @@
140118
},
141119
{
142120
"cell_type": "code",
143-
"execution_count": 110,
121+
"execution_count": null,
144122
"metadata": {},
145-
"outputs": [
146-
{
147-
"data": {
148-
"text/plain": [
149-
"3"
150-
]
151-
},
152-
"execution_count": 110,
153-
"metadata": {},
154-
"output_type": "execute_result"
155-
}
156-
],
123+
"outputs": [],
157124
"source": [
158125
"n = 5\n",
159126
"Solution().getMaximumGenerated(n)"
160127
]
161128
},
129+
{
130+
"cell_type": "code",
131+
"execution_count": null,
132+
"metadata": {},
133+
"outputs": [],
134+
"source": []
135+
},
136+
{
137+
"cell_type": "code",
138+
"execution_count": null,
139+
"metadata": {},
140+
"outputs": [],
141+
"source": [
142+
"import os\n",
143+
"os.getcwd()"
144+
]
145+
},
146+
{
147+
"cell_type": "code",
148+
"execution_count": null,
149+
"metadata": {},
150+
"outputs": [],
151+
"source": [
152+
"import csv\n",
153+
"import PyPDF2\n",
154+
"\n",
155+
"# Open the PDF file\n"
156+
]
157+
},
158+
{
159+
"cell_type": "code",
160+
"execution_count": null,
161+
"metadata": {},
162+
"outputs": [],
163+
"source": [
164+
"pdf_file = open(\"RNW 3Q'23 Earnings_vF.pdf\", 'rb')\n",
165+
"\n",
166+
"\n",
167+
"\"RNW 3Q'23 Earnings_vF.pdf\"\n",
168+
"\n",
169+
"\n",
170+
"\"Rehire-Policy-_-Final-draft\""
171+
]
172+
},
173+
{
174+
"cell_type": "code",
175+
"execution_count": null,
176+
"metadata": {},
177+
"outputs": [],
178+
"source": [
179+
"import csv\n",
180+
"from pdfminer.high_level import extract_text\n",
181+
"\n",
182+
"# Extract the text from the PDF file\n",
183+
"text = extract_text('Rehire-Policy-_-Final-draft.pdf')\n",
184+
"\n",
185+
"# Create a CSV file to write the extracted text\n",
186+
"csv_file = open('example.csv', 'w', newline='')\n",
187+
"csv_writer = csv.writer(csv_file)\n",
188+
"\n",
189+
"# Write the text to the CSV file\n",
190+
"csv_writer.writerow([text])\n",
191+
"\n",
192+
"# Close the CSV file\n",
193+
"csv_file.close()\n"
194+
]
195+
},
196+
{
197+
"cell_type": "code",
198+
"execution_count": null,
199+
"metadata": {},
200+
"outputs": [],
201+
"source": [
202+
"print(text)"
203+
]
204+
},
205+
{
206+
"cell_type": "code",
207+
"execution_count": null,
208+
"metadata": {},
209+
"outputs": [],
210+
"source": [
211+
"import openpyxl\n",
212+
"from pdfminer.high_level import extract_pages, extract_text\n",
213+
"\n",
214+
"# Create an Excel workbook\n",
215+
"workbook = openpyxl.Workbook()\n",
216+
"\n",
217+
"# Extract the pages from the PDF file and save each page into a separate sheet in the workbook\n",
218+
"for page_num, page_layout in enumerate(extract_pages(\"RNW 3Q'23 Earnings_vF.pdf\"), start=1):\n",
219+
" # Create a new sheet in the workbook\n",
220+
" sheet_name = f'Page {page_num}'\n",
221+
" worksheet = workbook.create_sheet(sheet_name)\n",
222+
"\n",
223+
" # Extract the text from the page layout\n",
224+
" text = extract_text(page_layout)\n",
225+
"\n",
226+
" # Split the text into lines and write each line to a row in the sheet\n",
227+
" lines = text.split('\\n')\n",
228+
" for row_num, line in enumerate(lines, start=1):\n",
229+
" worksheet.cell(row=row_num, column=1, value=line)\n",
230+
"\n",
231+
"# Save the workbook\n",
232+
"workbook.save('Renew-Power-Prospectus.xlsx')\n"
233+
]
234+
},
235+
{
236+
"cell_type": "code",
237+
"execution_count": null,
238+
"metadata": {},
239+
"outputs": [],
240+
"source": [
241+
"text = extract_text(page_layout)"
242+
]
243+
},
244+
{
245+
"cell_type": "code",
246+
"execution_count": null,
247+
"metadata": {},
248+
"outputs": [],
249+
"source": [
250+
"page_layout"
251+
]
252+
},
253+
{
254+
"cell_type": "code",
255+
"execution_count": null,
256+
"metadata": {},
257+
"outputs": [],
258+
"source": [
259+
"\n",
260+
"\n",
261+
"\n",
262+
"# Create a CSV file to write the extracted text\n",
263+
"csv_file = open('example.csv', 'w', newline='')\n",
264+
"csv_writer = csv.writer(csv_file)\n",
265+
"\n",
266+
"# Loop through each page in the PDF file\n",
267+
"for page_num in range(num_pages):\n",
268+
" # Get the page object\n",
269+
" page = pdf_reader.getPage(page_num)\n",
270+
"\n",
271+
" # Extract the text from the page\n",
272+
" text = page.extractText()\n",
273+
"\n",
274+
" # Write the text to the CSV file\n",
275+
" csv_writer.writerow([text])\n",
276+
"\n",
277+
"# Close the CSV file and PDF file\n",
278+
"csv_file.close()\n",
279+
"pdf_file.close()"
280+
]
281+
},
282+
{
283+
"cell_type": "code",
284+
"execution_count": null,
285+
"metadata": {},
286+
"outputs": [],
287+
"source": []
288+
},
162289
{
163290
"cell_type": "code",
164291
"execution_count": null,

0 commit comments

Comments
 (0)