首页 > 其他 > 详细

leetcode1288

时间:2019-12-15 09:54:33      阅读:94      评论:0      收藏:0      [点我收藏+]
 1 import itertools
 2 class CombinationIterator:
 3 
 4     def __init__(self, characters: str, combinationLength: int):
 5         self.lists = list(itertools.combinations(characters,combinationLength))
 6         self.index = 0
 7 
 8     def next(self) -> str:
 9         tp = self.lists[self.index]
10         self.index += 1
11         return ‘‘.join(tp)
12 
13     def hasNext(self) -> bool:
14         return self.index < len(self.lists)

直接调用itertools内置函数,快速生成符合条件的组合。

1286. Iterator for Combination

leetcode1288

原文:https://www.cnblogs.com/asenyang/p/12041720.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!