whosyourdaddy 发表于 2020-3-5 17:23:20

def func342(n):
    count = 0
    list1 = list(n)
    list2 = sorted(set(list1),key=list1.index)
    for i in list2:
      if list1.count(i)%2 == 0:
            continue
      elif list1.count(i)%2 == 1:
            count += 1
            if count == 2:
                break
    if count == 2:
      return False
    return True

wuqramy 发表于 2020-3-5 18:01:14

zltzlt 发表于 2020-3-5 13:19
32 ms

不测了?

Lyton_ 发表于 2020-3-5 18:18:44

zltzlt 发表于 2020-3-5 13:16
解答错误

输入:"aaa"


def fun342(str1):
    count=0
    for each in str1:
      count+=str1.count(each)%2      
    if count>1 and count<len(str1):
      print('False')
    else:
      print('True')


str1=input('请输入需要判断的字符串:')
fun342(str1)

zltzlt 发表于 2020-3-6 08:22:14

cwm19860924 发表于 2020-3-4 22:29
str1=input('>>>')
flag= 1#1True符合题意0False不合题意
num = 0# 有0或1个字符单独出现时,符 ...

下次请写成一个函数哦~{:10_275:}

zltzlt 发表于 2020-3-6 08:23:51

huainian2333 发表于 2020-3-5 16:12
def count():
    odd_n = 0
    coun = 0


28 ms

zltzlt 发表于 2020-3-6 08:24:17

whosyourdaddy 发表于 2020-3-5 17:23
def func342(n):
    count = 0
    list1 = list(n)


40 ms

zltzlt 发表于 2020-3-6 08:25:01

Lyton_ 发表于 2020-3-5 18:18


解答错误

输入:"code"
输出:True
预期结果:False

永恒的蓝色梦想 发表于 2020-3-12 09:08:13

yexing 发表于 2020-3-3 19:58
暂时只想到了这种笨方法,传入大数据可能会超时

感觉不是必须用尽量不要用permutations{:10_248:}

永恒的蓝色梦想 发表于 2020-3-12 09:17:13

本帖最后由 永恒的蓝色梦想 于 2020-3-12 09:22 编辑

class Solution:
    def canPermutePalindrome(self, s: str) -> bool:
      w={}
      k=False
      
      for i in s:
            w=not w.get(i,k)
            
      for i in w:
            if w:
                if k:
                  return False
                else:
                  k=True
      
      return True

catwine1990 发表于 2020-3-14 21:33:06

'''
给定一个字符串,编写一个函数判定其是否为某个回文串的排列之一。
奇数字符小于等于1——>True
奇数字符大于1——>False
'''
def fun342():
    a=input('请输入一个字符串:')
    odd = 0
    for each in a:
      if a.count(each) % 2 !=0:
            odd += 1
    if odd > 1:
      return False
    else:
      return True

songpeijue 发表于 2020-3-15 10:53:33

str1=input('请输入您要检验的序列:')
length=len(str1)
list1=[]
odd=0

for i in range(length):
    while str1 not in list1:
      if (str1.count(str1))%2 == 1:
            odd+=1
      else:
            odd+=0
      list1.append(str1)
   
if odd<2:
    print('True')
else:
    print('False')

776667 发表于 2020-12-15 10:05:00

def fun342(x):
    set_x = set(x)
    count_x =
    odd_count =
    if len(odd_count) >= 2:
      return False
    return True
页: 1 2 3 4 5 6 [7]
查看完整版本: Python:每日一题 342