-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Some Basic Easy Problems ( Python )
- Loading branch information
SpiderX
authored
Sep 30, 2022
1 parent
0bcd13e
commit 5f5cb24
Showing
6 changed files
with
123 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |