Skip to content

Commit

Permalink
Added Some Basic Easy Problems ( Python )
Browse files Browse the repository at this point in the history
  • Loading branch information
SpiderX authored Sep 30, 2022
1 parent 0bcd13e commit 5f5cb24
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Contains_Duplicate_217.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
def CN217(nums):
array = nums
for i in range(len(array)):
if array.count(array[i]) > 1:
return print('true')
exit()
else:
if i == len(array)-1:
return print('false')


if __name__=="__main__":
nums = [1,2,3,4]
CN217(nums)
13 changes: 13 additions & 0 deletions Move_Zeroes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
def MZ(nums):
root = nums
for i in range(len(root)):
if root[i] == 0:
root.remove(root[i])
root.append(0)

return print(root)


if __name__=="__main__":
nums = [0, 1, 3, 0, 15]
MZ(nums)
41 changes: 41 additions & 0 deletions Reverse_Words_in_a_String _II.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
def ReverseString(s):
getset = []
ls = list(s)
rtf = []
laststopage = 0
for i in range(len(ls)+1):
if i == len(ls):
rtf.append(s[laststopage:i])
fire = []
for k in range(len(rtf)+1):
if k == len(rtf):
print(*fire)
else:
fire.append((rtf[k][::-1]).replace(" ", ""))


elif ls[i] == " ":
rtf.append(s[laststopage:i])
laststopage = i


if __name__=="__main__":
words = "Himu Rupa Dhorsok"
ReverseString(words)

"""
Explanation
st="Hello Shagufta"
**split function break the string into words. **
eg: print(st.split(" "))-----['Hello', 'Shagufta']
If we use [::-1] it will revese the element of list
eg: print(st.split(" ")[::-1])----['Shagufta', 'Hello']
if we use [: : -1] with join function, it will reverse the element of list as well as letters of element.
eg: print(" ".join(st.split(" "))[::-1])----atfugahS olleH
so we apply two times [: : -1] to replace the elements to the oriinal index
eg: print(" ".join(st.split(" ")[::-1])[::-1]) ------olleH atfugahS
"""
17 changes: 17 additions & 0 deletions Sort_the_People.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
def STP(names, heights):
nm = names
hm = heights
nm_new = []
hm_sort = sorted(hm)
hm_sort.reverse()
for i in range(len(nm)):
z = hm_sort.index(hm[i])
nm_new.append(nm[z])

return print(nm_new)


if __name__=="__main__":
names =["GXLVEHVABFOGSFXUYYR","TUHxnsxmu","X","OOYBLVKmzlaeaxbprc","ARNLAPtfvmutkfsa","XPMKPDUWOQEEILtbdjip","QICEutjbr","R"]
heights = [11578,89340,73785,12096,55734,89484,59775,72652]
STP(names, heights)
19 changes: 19 additions & 0 deletions palindrone_number.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
def Palindrone(x):
if -2147483648 < x < 2147483648:
x = list(str(x))
rev_x = []
for i in range(len(x)):
rev_x.append(x[-(i+1)])
print(x)
print(rev_x)
if (rev_x == x):
print('true')
else:
print('false')
else:
exit()


if __name__=="__main__":
x = -121
Palindrone(x)
19 changes: 19 additions & 0 deletions two_sum.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
def TWO_SUMS(nums, target):
if 2 <= len(nums) <= 1000:
if -1000000000 <= target <= 1000000000:
for i in range(len(nums)):
for j in range(1, len(nums)):
if (nums[i] + nums[j]) == target:
if i == j:
pass
else:
return print([i, j])
break
else:
pass


if __name__=="__main__":
nums = [2, 3, 4, 6]
target = 10
TWO_SUMS(nums, target)

0 comments on commit 5f5cb24

Please sign in to comment.