Python类变量在方法结束后因未将Deepcopy应用于列表而发生更改

问题描述

试图使用回溯在python中解决这个leetcode问题-

String

获得此解决方案的奇怪输出-

double x = 10.567;
textView.setText(double);

输入:String.valueOf()

输出:

Given a string s,partition s such that every substring of the partition is a palindrome. 
Return all possible palindrome partitioning of s.

此代码有效,只需将class Solution: a = list() def backtrack(self,start,string,palindrome,stack): if start == len(string): self.a.append(stack) return if start == len(string)-1: stack.append(string[start]) self.a.append(stack) stack.pop() return for end in range(start,len(string)): if start == end: stack.append(string[start]) self.backtrack(start+1,stack) stack.pop() elif string[start] == string[end] and ((end == start+1) or palindrome[start+1][end-1]): stack.append(string[start:end+1]) palindrome[start][end] = True self.backtrack(end+1,stack) stack.pop() def partition(self,string): stack = [] self.a.clear() palindrome = [[False for __ in range(len(string))] for _ in range(len(string))] for i in range(len(string)): palindrome[i][i] = True self.backtrack(0,stack) return self.a 更改为aab并进行其他较小的更改

[[],[]]

输入:list

输出:set

问题:https://leetcode.com/problems/palindrome-partitioning/

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)