【发布时间】:2019-09-03 01:12:10
【问题描述】:
从用户那里获取整数输入,然后从数组中删除具有许多连续出现的数组中的元素。
例如,输入数组是“aabcca”,用户的输入是 2。 那么答案应该是“ba”。
我在元素不重复时尝试过。我的代码非常适合“aaabbccc”之类的示例。
for j in range(t, (n+1)):
if (t == n):
if (count == k):
array = [x for x in array if x != temp]
print array
exit()
if (t == n and count == k):
array = [x for x in array if x != temp]
print array
exit()
if temp == data[j]:
count += 1
t += 1
if temp != data[j]:
if count == k:
array = [x for x in array if x != temp]
temp = data[t]
count = 1
t += 1
【问题讨论】:
-
你能解释一下为什么
input array is "aabcca" and the input from the user is 2. Then the answer should be "ba".吗? -
@recnac 这是问题陈述。例如,如果您有一个字符串 aaabca 并且用户输入是 3,那么输出应该是 bca。只有用户提到的长度的连续字符应该被删除。另一个例子是如果数组是 abbcb 并且输入是 2 那么输出将是 acb。
-
谢谢,我一定是在某个地方迷路了@Atharva Biwalkar
标签: python arrays algorithm list