Python到c的转换。请将此代码转换为c语言

选择 | 换行 | 行号
  1. from collections import deque, Counter
  2.  
  3. class Solution:
  4.     def smallestRange(self, nums: List[List[int]]) -> List[int]:
  5.  
  6.         new = []
  7.         # merge each list and keep track of original list
  8.         for i in range(len(nums)):
  9.             for j in nums[i]:
  10.                 new.append((j, i))
  11.         # sort so each sliding window represents a range
  12.         new.sort()
  13.  
  14.         d = deque()
  15.         c = Counter()
  16.  
  17.         res = [-float('inf'), float('inf')]
  18.         # iterate over sliding windows that contain each list
  19.         for i in new:
  20.             d.append(i)
  21.             c[i[1]] += 1
  22.             while len(c) == len(nums):
  23.                 res = min(res, [d[0][0], d[-1][0]], key = lambda x: x[1] - x[0])
  24.                 a, b = d.popleft()
  25.                 c[b] -= 1
  26.                 if not c[b]: del c[b]
  27.         return res
# 回答1

请务必查看张贴指南。

标签: python

添加新评论