纪念一下,第一次AK(老虎集团)
第一题
# # 按频率高低打印 # @param s string字符串 输入字符 # @return string字符串 # import collections class Solution: def frequencySort(self, s): # write code here a = collections.Counter(s) a = dict(a) b = sorted(a.items(), key=lambda a: a[1], reverse=True) ans = "" for i in b: ans += i[0] * i[1] return ans第二题
# # 路径总和最小 # @param arr int整型二维数组 入参 # @return int整型 # class Solution: def uniquePaths(self, arr): # write code here m = len(arr) # 行 n = len(arr[0]) # 列 dp = [[float('inf')] * n for _ in range(m)] dp[0][0] = arr[0][0] for i in range(1, m): dp[i][0] = arr[i][0] + dp[i - 1][0] for i in range(1, n): dp[0][i] = arr[0][i] + dp[0][i-1] for i in range(1, m): for j in range(1, n): dp[i][j] = min(dp[i - 1][j], dp[i][j - 1]) + arr[i][j] return dp[-1][-1]