Skip to content

Commit 3988658

Browse files
Adding some files
1 parent 51d82bf commit 3988658

File tree

3 files changed

+94
-14
lines changed

3 files changed

+94
-14
lines changed

Python/chapter01/1.3 - URLify/camilo_solution_1.3.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,21 @@
55
(Note: If implementing in Java,please use a character array so that you can
66
perform this operation in place.)
77
EXAMPLE
8-
Input: "Mr John Smith ", 13 Output: "Mr%20John%20Smith"
8+
Input: "Mr John Smith ", 13 Output: "Mr%20John%20Smith"
99
"""
1010

1111
def urlify(str):
12+
len_ = len(str) #gets the lenght of str
13+
new_str = ""#build a new string
14+
for i in range(len_-1):
15+
if str[i] == " " and str[i+1]==" ":#if two space aheah are space then break
16+
break
17+
if str[i] == " ": #if we find a space just add %20
18+
new_str+= "%20"
19+
20+
else: #just add the chars
21+
new_str+= str[i]
22+
23+
return new_str
24+
25+
print(urlify("MY house is on fire "))

Python/chapter02/2.7 - Intersection/camilo_soultion_2.7.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -161,18 +161,19 @@ def intersection(listA,ListB):
161161

162162
# 1->2->3->4->5->6->7
163163
# 3->5->6->7
164-
llist_1 = linklist()
165-
llist_2 = linklist()
166-
llist_1.push(1)
167-
llist_1.push(3)
168-
llist_1.push(5)
169-
llist_1.push(7)
170-
llist_1.push(9)
171-
llist_1.push(11)
172-
173-
llist_2.push(2)
174-
llist_2.push(4)
175-
llist_2.push(9)
176-
llist_2.push(11)
164+
class Test(TestCase):
165+
def setUp():
166+
llist_1 = linklist()
167+
llist_2 = linklist()
168+
llist_1.push(1)
169+
llist_1.push(3)
170+
llist_1.push(5)
171+
llist_1.push(7)
172+
llist_1.push(9)
173+
llist_1.push(11)
174+
llist_2.push(2)
175+
llist_2.push(4)
176+
llist_2.push(9)
177+
llist_2.push(11)
177178

178179
print(intersection(llist_1,llist_2))
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
class stack:
2+
def __init__(self):
3+
self.arr = []
4+
5+
def push(self,item):
6+
"""
7+
Add an item to the top of the stack.
8+
"""
9+
self.arr.insert(0,item)
10+
11+
def pop_():
12+
"""
13+
Remove the top item from the stack.
14+
"""
15+
arr = self.arr
16+
len_ = len(arr)
17+
return self.arr.pop(arr)
18+
19+
20+
def peek(self):
21+
"""
22+
Return the top of the stack.
23+
"""
24+
return self.arr[0]
25+
26+
def isEmpty():
27+
"""
28+
Return true if and only if the stack is empty.
29+
"""
30+
if self.arr == None:
31+
return True
32+
return False
33+
34+
35+
36+
class queue:
37+
def __init__(self):
38+
self.arr = []
39+
40+
def add(self,item):
41+
"""
42+
Add an item to the end of the list.
43+
"""
44+
self.arr.append(item)
45+
46+
47+
def remove(self):
48+
"""
49+
Remove the first item in the list.
50+
"""
51+
return self.arr.pop(0)
52+
53+
def peek(self):
54+
"""
55+
Return the top of the queue.
56+
"""
57+
return self.arr[0]
58+
59+
def isEmpty():
60+
"""
61+
Return true if and only if the queue is empty.
62+
"""
63+
if self.arr == None:
64+
return True
65+
return False

0 commit comments

Comments
 (0)