-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharrayandstring.py
More file actions
125 lines (104 loc) · 2.39 KB
/
arrayandstring.py
File metadata and controls
125 lines (104 loc) · 2.39 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
def isUnique(list):
char = []
for x in list:
if char.count(x) > 0:
return False
else:
char.append(x)
return True
# Time complexity:O(n)
def urlify(s):
temp = []
for x in s:
if x.isspace():
temp.append("%20")
else:
temp.append(x)
string = "".join(temp)
return string
def check_permutation(s1, s2):
temp = []
if len(s2) > len(s1):
return False
else:
for x in s1:
temp.append(x)
for i in s2:
if temp.count(i) == 0:
return False
return True
def pal_per(string):
temp = []
for x in string:
if temp.count(x) > 0:
temp.remove(x)
else:
temp.append(x)
if len(temp) == 1:
return True
else:
return False
def oneAway(s1, s2):
temp = []
for x in s1:
temp.append(x)
for i in s2:
if temp.count(i) > 0:
temp.remove(i)
if len(temp) == 1:
return True
else:
return False
def string_compression(string):
s1 = []
s2 = []
character = ""
for x in string:
s1.append(x)
for i in string:
if s2.count(i) < 1:
s2.append(i)
if len(s1) == len(s2):
string = "".join(s2)
return string
for z in s2:
c = s1.count(z)
character = character + z + str(c)
return character
def rotate(matrix):
matrix.reverse()
for i in range(len(matrix)):
for j in range(i):
matrix[j][i], matrix[i][j] = matrix[i][j], matrix[j][i]
print(matrix)
def zero(m):
for i in range(len(m)):
j = 0
while j<len(m):
m[i][j] = 0
j+=1
print(m)
def zero_matrix(m):
for i in range(len(m)):
j = 0
while j<len(m):
if m[i][j] ==0:
zero(m)
return
else:
j+=1
print(m)
def isSubstring(s1,s2):
string1 = len(s1)
string2 = len(s2)
if string1 !=string2:
return False
temp = s1 + s2
bho = temp.count(s2)
print(temp.count(s2))
if temp.count(s2)>0:
return True
else:
return False
if __name__ == "__main__":
print(isSubstring("waterbottle","erbottlewat"))