Python 面试题整理

  1. 请用Python程式或你擅长的语言写出下面问题的答案

(1).一个不固定长度的字串,找出连续最长的0或连续最长的1 

      [提示1]: "1110001111" 其中连续313041 --->程式反馈结果要是最长的是41

      [提示2]: "1010001010" ---> 程式反馈结果最长的是30

      [提示3]: 题目问的是不固定长度(N)的一组字串,ex:"len(010101011100011111110001010111111...) isN"

def findMaxLenForSameChar(strValue):
    index, count, list = 0, 0, []
    if len(strValue) == 1:
        return (count + 1, strValue[index])
    else:
        for i in range(1, len(strValue)):
            if strValue[index] == strValue[i]:
                index, count = index + 1, count + 1
            else:
                list.append((count + 1, strValue[index]))
                index, count = index + 1, 0
            if i == len(strValue) - 1:
                list.append((count + 1, strValue[index]))
        return  max(list)
    return list


(2).有一个字串  "I will go to Jinan and see a move !!!",请用寫程式 将他反转输出为"!!! move a see and Jinan to go will I"

def reverseWorld(strValue):
    import re
    revwords = re.split(r'(\s+)', strValue)
    revwords.reverse()
    return ''.join(revwords)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值