@@ -1248,8 +1248,79 @@ def divisibilityArray(self, word: str, m: int) -> List[int]:
12481248 ans .append (0 )
12491249 return ans
12501250
1251- def maxNumOfMarkedIndices (self , nums : List [int ]) -> int :
1251+ def minMaxDifference (self , num : int ) -> int :
1252+ s = [i for i in str (num )]
1253+ n = len (s )
1254+ minnum = []
1255+ maxnum = []
1256+ for i in range (n ):
1257+ if minnum and maxnum :
1258+ return int ("" .join (maxnum )) - int ("" .join (minnum ))
1259+ else :
1260+ if s [i ] != "0" and not minnum :
1261+ minnum = [char if char != s [i ] else "0" for char in s ]
1262+ if s [i ] != "9" and not maxnum :
1263+ maxnum = [char if char != s [i ] else "9" for char in s ]
1264+ if not maxnum :
1265+ maxnum = s
1266+ if not minnum :
1267+ minnum = s
1268+ return int ("" .join (maxnum )) - int ("" .join (minnum ))
1269+
1270+ def countVowelStrings (self , n : int ) -> int :
1271+ dp = [[1 ]* 5 for _ in range (n )]
1272+ for i in range (1 , n ):
1273+ for j in range (5 ):
1274+ dp [i ][j ] = sum ( dp [i - 1 ][:j + 1 ] )
1275+ return sum (dp [- 1 ])
1276+
1277+ def generateParenthesis (self , n : int ) -> List [str ]:
1278+ dp = ["()" ]
1279+ for i in range (1 , n ):
1280+ temp = {}
1281+ for s in dp :
1282+ temp [s + "()" ] = 1
1283+ temp [f"({ s } )" ] = 1
1284+ temp ["()" + s ] = 1
1285+ dp = list (temp .keys ())
1286+ return dp
1287+
1288+ def countBits (self , n : int ) -> List [int ]:
1289+ def compute (num ):
1290+ ans = 0
1291+ while num :
1292+ ans += num % 2
1293+ num //= 2
1294+ return ans
1295+ ans = [compute (i ) for i in range (n + 1 )]
1296+ return ans
12521297
1298+ def numberOfBeams (self , bank : List [str ]) -> int :
1299+ ans = 0
1300+ pre = sum (int (i ) for i in bank [0 ])
1301+ for i in range (1 , len (bank )):
1302+ temp = sum (int (i ) for i in bank [i ])
1303+ if temp == 0 :
1304+ continue
1305+ else :
1306+ ans += temp * pre
1307+ pre = temp
1308+ return ans
1309+
1310+ def totalMoney (self , n : int ) -> int :
1311+ """
1312+
1313+ 第i个星期, i + 3 块钱
1314+ 第j天
1315+ :param n:
1316+ :return:
1317+ """
1318+ ans = 0
1319+ week = n // 7
1320+ for i in range (week ):
1321+ ans += 7 * (i + 4 )
1322+ day = n % 7
1323+ for i in range (day ):
1324+ ans += week + 1 + i
1325+ return ans
12531326
1254- s = Solution ()
1255- print (s .maxTotalReward ( [1 ,6 ,4 ,3 ,2 ]))
0 commit comments