Merge branch 'master' of http://ff.mhrooz.xyz:3000/iicd/leetcode
This commit is contained in:
		
							
								
								
									
										25
									
								
								125-240524-pass/main.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								125-240524-pass/main.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,25 @@ | |||||||
|  | def isPalindrome(s: str) -> bool: | ||||||
|  |     tmp = s | ||||||
|  |     tmp = tmp.lower() | ||||||
|  |     def is_char(ch): | ||||||
|  |         if (ch >= 'a' and ch <= 'z') or (ch >= '0' and ch <= '9'): | ||||||
|  |             return True | ||||||
|  |         return False | ||||||
|  |     exp = [] | ||||||
|  |     for lt in tmp: | ||||||
|  |         if is_char(lt): | ||||||
|  |             exp.append(lt) | ||||||
|  |     length = len(exp) | ||||||
|  |     for index, ele in enumerate(exp): | ||||||
|  |         if(exp[index] != exp[length - index - 1]): | ||||||
|  |             return False | ||||||
|  |     return True | ||||||
|  |  | ||||||
|  | s = 'A man, a plan a canal: Panama' | ||||||
|  | print(isPalindrome(s)) | ||||||
|  | s = " " | ||||||
|  | print(isPalindrome(s)) | ||||||
|  | s = "race a car" | ||||||
|  | print(isPalindrome(s)) | ||||||
|  | s = "0P" | ||||||
|  | print(isPalindrome(s)) | ||||||
							
								
								
									
										42
									
								
								88-231127-pass/main.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										42
									
								
								88-231127-pass/main.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,42 @@ | |||||||
|  | def merge(self, nums1: list[int], m: int, nums2: list[int], n: int) -> None: | ||||||
|  |         """ | ||||||
|  |         Do not return anything, modify nums1 in-place instead. | ||||||
|  |         """ | ||||||
|  |         tmp = [] | ||||||
|  |         for i in range(m): | ||||||
|  |             tmp.append(nums1[i]) | ||||||
|  |         for num in nums2: | ||||||
|  |             tmp.append(num) | ||||||
|  |          | ||||||
|  |         ind1 = 0 | ||||||
|  |         ind2 = 0 | ||||||
|  |         rlt = [] | ||||||
|  |         if(m == 0 or n == 0): | ||||||
|  |             rlt += tmp | ||||||
|  |         else: | ||||||
|  |             for i in range(m + n): | ||||||
|  |                 if(nums1[ind1]<= nums2[ind2]): | ||||||
|  |                     rlt.append(nums1[ind1]) | ||||||
|  |                     ind1 += 1 | ||||||
|  |                     if(ind1 == m): | ||||||
|  |                         rlt += nums2[ind2:] | ||||||
|  |                         print(i, rlt) | ||||||
|  |                         break | ||||||
|  |                 else: | ||||||
|  |                     rlt.append(nums2[ind2]) | ||||||
|  |                     ind2 += 1 | ||||||
|  |                     if(ind2 == n): | ||||||
|  |                         rlt += nums1[ind1:] | ||||||
|  |                         print(i, rlt) | ||||||
|  |                         break; | ||||||
|  |                 print(i, rlt) | ||||||
|  |         for i in range(len(rlt)): | ||||||
|  |             nums1[i] = rlt[i] | ||||||
|  |  | ||||||
|  | nums1 = [2,0] | ||||||
|  | m = 1 | ||||||
|  | nums2 = [1] | ||||||
|  | n = 1 | ||||||
|  | print(merge(0, nums1, m, nums2, n)) | ||||||
|  |  | ||||||
|  |      | ||||||
		Reference in New Issue
	
	Block a user