Skip to content

Commit 2d9ba4e

Browse files
committed
code changes
1 parent 02694bc commit 2d9ba4e

11 files changed

+279
-2
lines changed

Codepedia.code-workspace

+14-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,20 @@
66
],
77
"settings": {
88
"files.associations": {
9-
"iterator": "cpp"
9+
"iterator": "cpp",
10+
"__node_handle": "cpp",
11+
"__split_buffer": "cpp",
12+
"array": "cpp",
13+
"deque": "cpp",
14+
"list": "cpp",
15+
"map": "cpp",
16+
"queue": "cpp",
17+
"set": "cpp",
18+
"stack": "cpp",
19+
"string": "cpp",
20+
"string_view": "cpp",
21+
"unordered_map": "cpp",
22+
"vector": "cpp"
1023
}
1124
}
1225
}
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
s = input().strip()
2+
a = ['K']
3+
for i in s:
4+
if a[-1]==i:
5+
a.pop()
6+
else:
7+
a.append(i)
8+
if len(a)==1:
9+
print("Yes")
10+
else:
11+
print("No")
12+
13+
14+
#try 2
15+
16+
s=[]
17+
for i in input():
18+
if s and s[-1]==i:s.pop()
19+
else:s.append(i)
20+
print('Yneos'[bool(s)::2])
+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#include <iostream>
2+
#include <string>
3+
#include <stack>
4+
using namespace std;
5+
6+
7+
int main()
8+
{
9+
string s;
10+
cin>>s;
11+
stack<char> sta;
12+
for(int i=0;i<s.length();i++)
13+
{
14+
if(sta.empty())
15+
{
16+
sta.push(s.at(i));
17+
continue;
18+
}
19+
char ch = sta.top();
20+
if(s.at(i)!=ch)
21+
{
22+
sta.push(s.at(i));
23+
}else
24+
{
25+
sta.pop();
26+
}
27+
}
28+
stack<char> sta1;
29+
while(!sta.empty())
30+
{
31+
sta1.push(sta.top());
32+
sta.pop();
33+
}
34+
while(!sta1.empty())
35+
{
36+
cout<<sta1.top();
37+
sta1.pop();
38+
}
39+
40+
return 0;
41+
}

Gen2_0_PP/Homeworks/codeforces_81A.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
s = []
2+
for t in raw_input():
3+
if len(s) < 1:
4+
s.append(t)
5+
elif t == s[-1]:
6+
s.pop()
7+
else:
8+
s.append(t)
9+
print ''.join(s)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
class CustomStack:
2+
3+
def __init__(self, maxSize: int):
4+
self.item = []
5+
self.size = 0
6+
self.maxsize = maxSize
7+
8+
def push(self, x: int) -> None:
9+
if self.size < self.maxsize:
10+
self.item.append(x)
11+
self.size+=1
12+
13+
def pop(self) -> int:
14+
if self.size >0:
15+
self.size-=1
16+
return self.item.pop()
17+
else:
18+
return -1
19+
20+
def increment(self, k: int, val: int) -> None:
21+
for i in range(k):
22+
if i < self.size:
23+
self.item[i] += val
24+
else:
25+
break
26+
27+
28+
# Your CustomStack object will be instantiated and called as such:
29+
# obj = CustomStack(maxSize)
30+
# obj.push(x)
31+
# param_2 = obj.pop()
32+
# obj.increment(k,val)
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
class Node:
2+
def __init__(self, val=None, mini=None, next=None):
3+
self.val = val
4+
self.minimum = mini
5+
self.next = next
6+
7+
class MinStack:
8+
9+
def __init__(self):
10+
self.head = None
11+
12+
def push(self, x: int) -> None:
13+
if self.head is None:
14+
node = Node(x, x)
15+
self.head = node
16+
else:
17+
node = Node(x, min(x, self.head.minimum), self.head)
18+
self.head = node
19+
20+
def pop(self) -> None:
21+
self.head = self.head.next
22+
23+
def top(self) -> int:
24+
return self.head.val
25+
26+
def getMin(self) -> int:
27+
return self.head.minimum
28+
29+
# Your MinStack object will be instantiated and called as such:
30+
# obj = MinStack()
31+
# obj.push(x)
32+
# obj.pop()
33+
# param_3 = obj.top()
34+
# param_4 = obj.getMin()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution:
2+
def simplifyPath(self, path: str) -> str:
3+
stack = []
4+
l = path.split('/')
5+
for i in range(len(l)):
6+
if(l[i]=='..' and len(stack)!=0):
7+
stack.pop()
8+
else:
9+
if(len(l[i])!=0 and l[i]!='.' and l[i]!='..'):
10+
stack.append(l[i])
11+
else:
12+
continue
13+
if(len(stack)==0):
14+
return "/"
15+
string = ""
16+
while(len(stack)!=0):
17+
string = '/' + stack.pop() + string
18+
return string

Gen2_0_PP/Homeworks/spoj_STPAR.py

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
n = int(input())
2+
queue = list(map(int,input().split()))
3+
4+
stack = []
5+
fix_order = 1
6+
keep_tracking = True
7+
is_order = True
8+
9+
while (keep_tracking):
10+
q1 = queue[0] if len(queue) > 0 else -1
11+
s1 = stack[-1] if len(stack) > 0 else -1
12+
13+
if q1 == fix_order:
14+
del queue[0]
15+
fix_order = fix_order + 1
16+
continue
17+
18+
if s1 == fix_order:
19+
stack.pop()
20+
fix_order = fix_order + 1
21+
continue
22+
23+
if q1 != -1:
24+
del queue[0]
25+
stack.append(q1)
26+
continue
27+
28+
# DONE
29+
if q1 == -1 and s1 == -1:
30+
keep_tracking = False
31+
continue
32+
33+
#Can't order
34+
if q1 == -1 and s1 != fix_order:
35+
keep_tracking = False
36+
is_order = False
37+
38+
if is_order == False:
39+
print('no')
40+
else:
41+
print('yes')
42+
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
class Solution:
2+
def wordBreak(self, s: str, wordDict: List[str]) -> List[str]:
3+
d = {0: [], len(s): []}
4+
#values contain arrays of indices of all words that end at key index
5+
for ind, c in enumerate(s):
6+
if not ind in d: #we considered all indices before ind so skipping
7+
continue
8+
for w in wordDict:
9+
if s.startswith(w, ind):
10+
ind1 = ind + len(w)
11+
ar1 = d.get(ind1, [])
12+
if not ar1:
13+
d[ind1] = ar1
14+
ar1.append(ind)
15+
d1 = {0: [], len(s) : []}
16+
#Reconstruct all possible combinations back to index 0
17+
for ind in range(len(s), 0, -1):
18+
if not ind in d1:
19+
continue
20+
res = d1.get(ind, [])
21+
for i in d[ind]:
22+
res1 = [s[i: ind] + ' ' + ns for ns in res] if res else [s[i: ind]]
23+
res2 = d1.get(i, [])
24+
if not res2:
25+
d1[i] = res1
26+
else:
27+
res2.extend(res1)
28+
return d1[0]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution:
2+
def climbStairs(self, n: int) -> int:
3+
dp = [0]*n
4+
5+
for i in range(n):
6+
if (i == 0):
7+
dp[i] = 1
8+
elif (i == 1):
9+
dp[i] = 2
10+
else:
11+
dp[i] = dp[i-1]+dp[i-2]
12+
13+
return dp[-1]

Notebooks/TestNotebookCode.ipynb

+28-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
},
1515
"orig_nbformat": 2,
1616
"kernelspec": {
17-
"name": "python_defaultSpec_1596048486366",
17+
"name": "python_defaultSpec_1596114798131",
1818
"display_name": "Python 3.7.3 64-bit"
1919
}
2020
},
@@ -507,6 +507,33 @@
507507
"min(1,1)"
508508
]
509509
},
510+
{
511+
"cell_type": "code",
512+
"execution_count": 1,
513+
"metadata": {},
514+
"outputs": [],
515+
"source": [
516+
"a = [1,2,3,4,5]\n"
517+
]
518+
},
519+
{
520+
"cell_type": "code",
521+
"execution_count": 9,
522+
"metadata": {},
523+
"outputs": [
524+
{
525+
"output_type": "execute_result",
526+
"data": {
527+
"text/plain": "5"
528+
},
529+
"metadata": {},
530+
"execution_count": 9
531+
}
532+
],
533+
"source": [
534+
"a[-1]"
535+
]
536+
},
510537
{
511538
"cell_type": "code",
512539
"execution_count": null,

0 commit comments

Comments
 (0)