-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathleetcode_function.py
More file actions
106 lines (91 loc) · 3.72 KB
/
leetcode_function.py
File metadata and controls
106 lines (91 loc) · 3.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import pyperclip as pypc
from IPython.display import display, Javascript
import time
import webbrowser
class LeetFunction:
'''
This function is generated by Chandrashekhar Robbi.
This function can create the markdown and comment by justing entering your message by calling new function
It has also additional features like as you enter the message and run the cell the comment is automatically gets copied in your clipboard
the default value for comment is 4 i.e 4*#
You can change the value by taking whatever number you want
it has functions like
new(string) -> For creating new comment, markdown
printArr() -> to print the content of the arr
removeLastelement() -> remove the last element from the list
removeByUsingIndex(x) -> remove by using index
makeNullArr() -> to make empty list
'''
def __init__(self, url):
self.arr = []
self.delete = False
print("This Function is Created by Chandrashekhar Robbi.\nNote this function is especially created for my leet code solving purposes \nIt takes name of the problem and return leetcode link and it has features like create array which has markdown, comment and delete after executing and many more :)")
webbrowser.open_new_tab(url)
webbrowser.open_new_tab("https://leetcode.com/crobbi/")
def delete_cell_prev(self):
display(Javascript('''
var cell_index = IPython.notebook.get_selected_index();
var prev = cell_index - 1;
IPython.notebook.delete_cell(prev);
'''))
def delete_cell_curr(self):
display(Javascript('''
var cell_index = IPython.notebook.get_selected_index();
IPython.notebook.delete_cell(cell_index);
'''))
def to_markdown(self):
display(Javascript('''
IPython.notebook.to_markdown();
'''))
def jump_to_comment(self):
display(Javascript('''
IPython.notebook.select(1).edit_mode();
IPython.notebook.scroll_to_cell(3);
'''))
def new(self, s, h=2):
hash = "#"*h
link = "https://leetcode.com/problems/"
# print(s)
try:
text = "-".join(s.split(".")[1:][0].split()).lower()
except:
text = "-".join(s.split()).lower()
leet_link =link + text
leet_link
comment = f"* ✅ [{s}](#{s.replace(' ','-')}) [<a href='{leet_link}' style='color:black'>Link</a>]"
markdown = f"{hash} {s}\n\n* Approach:\n* Time Complexity $ O() $"
self.to_markdown()
if comment not in self.arr:
pypc.copy(markdown)
self.arr.append(comment)
print("Successfully added to the comment list")
print(f"Here is the link {leet_link}\nAll the best Chandrashekhar")
elif self.delete:
self.delete_cell_prev()
# self.to_markdown()
# time.sleep(1)
else:
print('It is already in the list')
# self.to_markdown()
# time.sleep(1)
# self.delete_cell_prev()
def printArr(self):
sum = ""
for i in range(len(self.arr)):
if i != len(self.arr) - 1:
sum += self.arr[i] + "\n"
else:
sum += self.arr[i]
print(i)
pypc.copy(sum)
self.delete_cell_prev()
self.jump_to_comment()
def removeLastelement(self):
self.arr.pop()
self.delete_cell_prev()
def removeByUsingIndex(self, x):
self.arr.pop(x)
self.delete_cell_prev()
def makeNullArr(self):
self.arr = []
self.delete_cell_prev()