当前位置:网站首页>Interview question 08.08 Permutation with duplicate strings
Interview question 08.08 Permutation with duplicate strings
2022-06-10 04:50:00 【Zi Yan Mu Yu】
topic
Interview questions 08.08. There are permutations and combinations of repeated strings
There are permutations and combinations of repeated strings . Write a method , Calculates all permutations of a string .
Example 1:
Input :S = “qqe”
Output :[“eqq”,“qeq”,“qqe”]
Example 2:
Input :S = “ab”
Output :[“ab”, “ba”]
Tips :
The characters are all English letters .
The string length is [1, 9] Between .
Their thinking
Add one set duplicate removal
Code
class Solution:
def permutation(self, S: str) -> List[str]:
return self.doIt(list(S), '')
def doIt(self, s: List[str], pre: str) -> List[str]:
size = len(s)
if size == 1:
return [pre + s[0]]
ans = []
have=set()
for i in range(size):
if s[0] not in have:
have.add(s[0])
ans += self.doIt(s[1:], pre + s[0])
if i < size - 1:
s[0], s[i + 1] = s[i + 1], s[0]
return ans
边栏推荐
- mindspore训练阶段报错:Not find op[Add] in akg
- Softing为艾默生提供AMS设备管理系统的连接解决方案
- Temporary global variables and iritemp database
- 微信手机端js小游戏踩方块源码
- 【深度学习】《PyTorch入门到项目实战》(十一):卷积层
- 2022G1工业锅炉司炉考试试题及答案
- MindSpore的nn.pad能否指定维度填充
- Powerful development board
- OpenJudge NOI 1.13 13:人民币支付
- Apispace sunrise sunset API interface is free and easy to use
猜你喜欢

Byte order, object class

深度学习与CV教程(13) | 目标检测 (SSD,YOLO系列)

【深度学习】《PyTorch入门到项目实战》(十一):卷积层

2022危险化学品经营单位主要负责人考试试题及在线模拟考试

2022g1 industrial boiler stoker examination questions and answers
![[depth first search] toy snake: maze problem](/img/9c/1c74ea1f7c9367a9bec4e1663a853a.png)
[depth first search] toy snake: maze problem

S series · several postures for deleting folders

MindSpore的nn.pad能否指定维度填充

Zero basic network: command line (CLI) debugging firewall practice

Detailed explanation of thread pool creation method
随机推荐
Yyds dry goods inventory solution sword finger offer: rectangular coverage
Briefly talk about the difference between routers and switches
MindSpore【初学入门】教程在线运行时报错
2022山东省安全员C证考试题库及答案
mindspore1.6conda安装gpu版本验证失败
信息学奥赛一本通 1287:最低通行费 | OpenJudge NOI 2.6 7614:最低通行费
2022.5.30-----leetcode. one thousand and twenty-two
- Oui. Net C # Foundation (7): Interface - Comment les gens interagissent avec les chats
ThreadLocal not yet? Come and have a look!
MindSpore的nn.pad能否指定维度填充
torch.randn迁移成mindspore.ops.TruncatedNormal使用问题
Distributed loading model and incremental training on shengteng 910
Tips for speeding up kettle insertion
Proteus仿真stm32f103R6Tx——外部中断控制LED亮灭(Cube MX+Keil5+proteus)
How to write OKR for test engineers to improve quality?
pytorch的add_module(name,module)用mindspore怎么表示
2022.5.26-----leetcode. six hundred and ninety-nine
【Linux篇<Day20>】——一文入门 数据库 和 容器技术
使用MindSpore在GPU-PYNATIVE/ CPU-GRAPH_MODE 与 GPU-GRAPH_MODE 执行不一致
Basic methods of stack and related problems