Skip to content

Commit ee82551

Browse files
few ready
1 parent 041ac85 commit ee82551

File tree

4 files changed

+135
-0
lines changed

4 files changed

+135
-0
lines changed

136 Single Number/solution.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Given a non-empty array of integers nums, every element appears twice except for one. Find that single one.
2+
#
3+
# You must implement a solution with a linear runtime complexity and use only constant extra space.
4+
5+
# Example 1:
6+
#
7+
# Input: nums = [2,2,1]
8+
# Output: 1
9+
# Example 2:
10+
#
11+
# Input: nums = [4,1,2,1,2]
12+
# Output: 4
13+
# Example 3:
14+
#
15+
# Input: nums = [1]
16+
# Output: 1
17+
18+
19+
nums = [4, 1, 2, 1, 2]
20+
21+
22+
def checknums(nums) -> int:
23+
24+
#dict style
25+
emtpy_dic = {}
26+
count = 0
27+
for i in nums:
28+
if i in emtpy_dic:
29+
emtpy_dic[i] += 1
30+
else:
31+
emtpy_dic[i] = 1
32+
# print(emtpy_dic)
33+
34+
35+
for k,v in emtpy_dic.items():
36+
if v == 1:
37+
return k
38+
39+
40+
print(checknums(nums))

20 Valid Parentheses/solution.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Given a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.
2+
#
3+
# An input string is valid if:
4+
#
5+
# Open brackets must be closed by the same type of brackets.
6+
# Open brackets must be closed in the correct order.
7+
# Every close bracket has a corresponding open bracket of the same type.
8+
#
9+
#
10+
# Example 1:
11+
#
12+
# Input: s = "()"
13+
#
14+
# Output: true
15+
16+
17+
s = "([])"
18+
19+
20+
def main(s) -> bool:
21+
stor = {
22+
"]" : "[",
23+
"}" : "{",
24+
")" : "("
25+
}
26+
stack = []
27+
28+
29+
30+
31+
print(main(s))

268 Missing Number/solution.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Given an array nums containing n distinct numbers in the range [0, n], return the only number in the range that is missing from the array.
2+
#
3+
#
4+
#
5+
# Example 1:
6+
#
7+
# Input: nums = [3,0,1]
8+
# Output: 2
9+
# Explanation: n = 3 since there are 3 numbers, so all numbers are in the range [0,3]. 2 is the missing number in the range since it does not appear in nums.
10+
11+
12+
nums = [3, 0, 1]
13+
14+
def missingnum(nums) -> int:
15+
16+
list1 = []
17+
18+
for i in range(0, len(nums)+1):
19+
list1.append(i)
20+
# print(list1)
21+
22+
for i in list1:
23+
if i not in nums:
24+
return i
25+
26+
27+
print(missingnum(nums))

58 Length of Last Word/solution.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Given a string s consisting of words and spaces, return the length of the last word in the string.
2+
#
3+
# A word is a maximal
4+
# substring
5+
# consisting of non-space characters only.
6+
#
7+
# Example 1:
8+
#
9+
# Input: s = "Hello World"
10+
# Output: 5
11+
# Explanation: The last word is "World" with length 5.
12+
# Example 2:
13+
#
14+
# Input: s = " fly me to the moon "
15+
# Output: 4
16+
# Explanation: The last word is "moon" with length 4.
17+
# Example 3:
18+
#
19+
# Input: s = "luffy is still joyboy"
20+
# Output: 6
21+
# Explanation: The last word is "joyboy" with length 6.
22+
#
23+
24+
s = " fly me to the moon "
25+
26+
def func(s) -> int:
27+
lis = s.split(" ")
28+
final_list = []
29+
30+
for i in lis:
31+
if i.isalpha():
32+
final_list.append(i)
33+
34+
return len(final_list[-1])
35+
36+
37+
print(func(s))

0 commit comments

Comments
 (0)