Skip to content

Commit bcfc976

Browse files
committed
updated
1 parent b44464c commit bcfc976

File tree

23 files changed

+435
-0
lines changed

23 files changed

+435
-0
lines changed

Hard_level/.DS_Store

6 KB
Binary file not shown.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
Given two sorted arrays nums1 and nums2 of size m and n respectively.
2+
3+
Return the median of the two sorted arrays.
4+
5+
Follow up: The overall run time complexity should be O(log (m+n)).
6+
7+
8+
9+
Example 1:
10+
11+
Input: nums1 = [1,3], nums2 = [2]
12+
Output: 2.00000
13+
Explanation: merged array = [1,2,3] and median is 2.
14+
Example 2:
15+
16+
Input: nums1 = [1,2], nums2 = [3,4]
17+
Output: 2.50000
18+
Explanation: merged array = [1,2,3,4] and median is (2 + 3) / 2 = 2.5.
19+
Example 3:
20+
21+
Input: nums1 = [0,0], nums2 = [0,0]
22+
Output: 0.00000
23+
Example 4:
24+
25+
Input: nums1 = [], nums2 = [1]
26+
Output: 1.00000
27+
Example 5:
28+
29+
Input: nums1 = [2], nums2 = []
30+
Output: 2.00000
31+
32+
33+
Constraints:
34+
35+
nums1,length == m
36+
nums2,length == n
37+
0 <= m <= 1000
38+
0 <= n <= 1000
39+
1 <= m + n <= 2000
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution:
2+
def findMedianSortedArrays(self, nums1: List[int], nums2: List[int]) -> float:
3+
nums1.extend(nums2)
4+
nums1.sort()
5+
if len(nums1)%2==0:
6+
# print("index1=",len(nums1)//2,"index2=",(len(nums1)//2)-1)
7+
# print("value1=",nums1[len(nums1)//2])
8+
# print("value2=",nums1[(len(nums1)//2)-1])
9+
# print("median=",(nums1[len(nums1)//2] +nums1[(len(nums1)//2)-1])/2)
10+
return (nums1[len(nums1)//2] +nums1[(len(nums1)//2)-1])/2
11+
else:
12+
# print("index=",len(nums1)//2)
13+
# print("median=",nums1[len(nums1)//2])
14+
return float(nums1[len(nums1)//2])
6 KB
Binary file not shown.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Given an array of 4 digits, return the largest 24 hour time that can be made.
2+
3+
The smallest 24 hour time is 00:00, and the largest is 23:59. Starting from 00:00, a time is larger if more time has elapsed since midnight.
4+
5+
Return the answer as a string of length 5. If no valid time can be made, return an empty string.
6+
7+
8+
9+
Example 1:
10+
11+
Input: [1,2,3,4]
12+
Output: "23:41"
13+
Example 2:
14+
15+
Input: [5,5,5,5]
16+
Output: ""
17+
18+
19+
Note:
20+
21+
1)A.length == 4
22+
2)0 <= A[i] <= 9
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
class Solution:
2+
def largestTimeFromDigits(self, A: List[int]) -> str:
3+
hour,mintue=0,0
4+
flag=False
5+
a,b=0,0
6+
time={}
7+
for i in range(0,4):
8+
for j in range(0,4):
9+
temp=(A[i]*10 + A[j])
10+
if i!=j and temp>=0 and temp<=23 :
11+
hour=A[i]*10 + A[j]
12+
i1,i2=i,j
13+
a,b=A[i1],A[i2]
14+
A[i1],A[i2]=None,None
15+
mintues=[A[k] for k in range(0,4) if A[k]!=None ]
16+
flag=True
17+
if mintues[0]>=mintues[1]:
18+
mintue= str(mintues[0]) + str(mintues[1])
19+
else:
20+
mintue= str(mintues[1]) + str(mintues[0])
21+
22+
if int(mintue) >=60:
23+
mintue=mintue[::-1]
24+
if int(mintue)>=60:
25+
flag=False
26+
if flag==True:
27+
time[hour]=mintue
28+
A[i1],A[i2]=a,b
29+
30+
if len(time) ==0:
31+
return ""
32+
else:
33+
hour=max(time.keys())
34+
mintue=time[hour]
35+
return str(hour//10)+str(hour%10)+":"+str(mintue)
36+
37+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Given a non-empty string check if it can be constructed by taking a substring of it and appending multiple copies of the substring together. You may assume the given string consists of lowercase English letters only and its length will not exceed 10000.
2+
3+
4+
5+
Example 1:
6+
7+
Input: "abab"
8+
Output: True
9+
Explanation: It's the substring "ab" twice.
10+
Example 2:
11+
12+
Input: "aba"
13+
Output: False
14+
Example 3:
15+
16+
Input: "abcabcabcabc"
17+
Output: True
18+
Explanation: It's the substring "abc" four times. (And the substring "abcabc" twice.)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class Solution:
2+
def repeatedSubstringPattern(self, s: str) -> bool:
3+
st=s[0]
4+
half=len(s)//2
5+
for i in range(0,half):
6+
# print("sub",st)
7+
# if len(st)%2 ==0:
8+
# pass
9+
# else:
10+
# pass
11+
rst=st[:]
12+
while len(rst) < len(s):
13+
rst=rst+st
14+
# print("str",rst)
15+
if rst==s:
16+
return True
17+
else:
18+
st=s[:i+2]
19+
# print("edsd==",st)
20+
return False
6 KB
Binary file not shown.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Given an array of integers, find out whether there are two distinct indices i and j in the array such that the absolute difference between nums[i] and nums[j] is at most t and the absolute difference between i and j is at most k.
2+
3+
Example 1:
4+
5+
Input: nums = [1,2,3,1], k = 3, t = 0
6+
Output: true
7+
Example 2:
8+
9+
Input: nums = [1,0,1,1], k = 1, t = 2
10+
Output: true
11+
Example 3:
12+
13+
Input: nums = [1,5,9,1,5,9], k = 2, t = 3
14+
Output: false

0 commit comments

Comments
 (0)