1010from math import sqrt
1111from operator import le
1212from typing import List
13+ import math
1314
1415
1516# from numpy import diff
2223
2324# oop
2425# from file name(module) import the class.
26+ from oop .Animals import Animals
27+ from oop .Tortoises import Tortoises
28+ from oop .Lion import Lion
29+
30+ greek = Tortoises ("福氣" ,"7個月大" ,"veggie" ,"地中海型陸龜" )
31+ greek .eat ()
32+ greek .environment ()
33+
34+ lion = Lion ("獅子" ,"未知" ,"肉食" )
35+ lion .environment ()
36+
2537# from oop.Fruit import Fruit
2638# from oop.Melon import Melon
2739# fruits = Fruit("Apple",3,5)
28- # print(fruits.calculate())
40+ # print("價格:",f"{ fruits.calculate()}" )
2941
30- # fruits = Fruit()
3142# fruits.make_watering()
3243
33- # v = Melon()
44+ # v = Melon("西瓜",65,10,30 )
3445# v.make_seedling()
3546# v.palnt()
3647
3748
38-
39- def diagonalDifference (arr ):
40- '''
41- Diagonal Difference
42- Complete the 'diagonalDifference' function below.
43-
44- The function is expected to return an INTEGER.
45- The function accepts 2D_INTEGER_ARRAY arr as parameter.
46- '''
47- left = 0
48- right = 0
49- for i in range (len (arr )):
50- left += arr [i ][i ]
51- right += arr [i ][len (arr ) - 1 - i ]
52- return abs (left - right )
53-
54-
55-
56-
5749'''
58501415. The k-th Lexicographical String of All Happy Strings of Length n
5951
@@ -221,53 +213,6 @@ def getFinalState(self, nums: List[int], k: int, multiplier: int) -> List[int]:
221213# print(a.getFinalState(nums,k,multiplier))
222214
223215
224-
225- '''
226- 3407. Substring Matching Pattern
227-
228- You are given a string s and a pattern string p, where p contains exactly one '*' character.
229- The '*' in p can be replaced with any sequence of zero or more characters.
230- Return true if p can be made a substring of s, and false otherwise.
231-
232- Hints:
233- 1. Divide the pattern in two strings and search in the string.
234-
235- Example 1:
236- Input: s = "leetcode", p = "ee*e"
237- Output: true
238- Explanation:
239- By replacing the '*' with "tcod", the substring "eetcode" matches the pattern.
240-
241- Example 2:
242- Input: s = "car", p = "c*v"
243- Output: false
244- Explanation:
245- There is no substring matching the pattern.
246-
247- Example 3:
248- Input: s = "luck", p = "u*"
249- Output: true
250- Explanation:
251- The substrings "u", "uc", and "uck" match the pattern.
252-
253- Constraints:
254- 1 <= s.length <= 50
255- 1 <= p.length <= 50
256- s contains only lowercase English letters.
257- p contains only lowercase English letters and exactly one '*'
258-
259- 參數為一個字串s和字串p,p內有一個"*"符號,而該符號可被替換成任一或多個字母
260- 若p的*號在替換成字母後可變成s的子字串,則回傳true
261- 否則false
262- '''
263- def hasMatch (s : str , p : str ) -> bool :
264- # 將字串拆成兩部分再搜尋
265- return False
266- # s = "leetcode"
267- # p = "ee*e"
268- # True
269- # print(hasMatch(s,p))
270-
271216'''
2722172523. Closest Prime Numbers in Range
273218
@@ -296,8 +241,6 @@ def hasMatch(s: str, p: str) -> bool:
296241
297242Constraints:
2982431 <= left <= right <= 106
299-
300-
301244'''
302245def closestPrimes (left : int , right : int ) -> List [int ]:
303246 '''
@@ -353,48 +296,3 @@ def isPrime(element:int):
353296# print(closestPrimes(left,right))
354297
355298
356- '''
357- 2873. Maximum Value of an Ordered Triplet I
358-
359- You are given a 0-indexed integer array nums.
360- Return the maximum value over all triplets of indices (i, j, k) such that i < j < k. If all such triplets have a negative value, return 0.
361- The value of a triplet of indices (i, j, k) is equal to (nums[i] - nums[j]) * nums[k].
362-
363- Hints:
364- 1.Use three nested loops to find all the triplets.
365-
366- Example 1:
367- Input: nums = [12,6,1,2,7]
368- Output: 77
369- Explanation: The value of the triplet (0, 2, 4) is (nums[0] - nums[2]) * nums[4] = 77.
370- It can be shown that there are no ordered triplets of indices with a value greater than 77.
371-
372- Example 2:
373- Input: nums = [1,10,3,4,19]
374- Output: 133
375- Explanation: The value of the triplet (1, 2, 4) is (nums[1] - nums[2]) * nums[4] = 133.
376- It can be shown that there are no ordered triplets of indices with a value greater than 133.
377- Example 3:
378-
379- Input: nums = [1,2,3]
380- Output: 0
381- Explanation: The only ordered triplet of indices (0, 1, 2) has a negative value of (nums[0] - nums[1]) * nums[2] = -3. Hence, the answer would be 0.
382-
383-
384- Constraints:
385- 3 <= nums.length <= 100
386- 1 <= nums[i] <= 106
387-
388- '''
389- def maximumTripletValue (nums : List [int ]) -> int :
390- # i < j < k
391- # (nums[i] - nums[j]) * nums[k]
392- ans = 0
393-
394- return ans
395-
396-
397- nums = [12 ,6 ,1 ,2 ,7 ]
398- # 77
399- # (0, 2, 4) is (nums[0] - nums[2]) * nums[4] = 77.
400- print (maximumTripletValue (nums ))
0 commit comments