huawei.py-20180413

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Apr  3 19:25:43 2018

@author: vicky
"""

def manacher(s):
    #预处理
    s='#'+'#'.join(s)+'#'

    RL=[0]*len(s)
    MaxRight=0
    pos=0
    MaxLen=0
    for i in range(len(s)):
        if i<MaxRight:
            RL[i]=min(RL[2*pos-i], MaxRight-i)
        else:
            RL[i]=1
        #尝试扩展,注意处理边界
        while i-RL[i]>=0 and i+RL[i]<len(s) and s[i-RL[i]]==s[i+RL[i]]:
            RL[i]+=1
        #更新MaxRight,pos
        if RL[i]+i-1>MaxRight:
            MaxRight=RL[i]+i-1
            pos=i
        #更新最长回文串的长度
        MaxLen=max(MaxLen, RL[i])
    return MaxLen-1

s='12321abc'
print(manacher(s))

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
解读下列编译报错:[OHOS INFO] ERROR at //build/templates/cxx/cxx.gni:242:7: Script returned non-zero exit code. [OHOS INFO] exec_script(external_deps_script, arguments) [OHOS INFO] ^---------- [OHOS INFO] Current dir: /home/huangjianli/kh3.2/out/khdvk_rk3568_a/ [OHOS INFO] Command: /usr/bin/env /home/huangjianli/kh3.2/build/templates/common/external_deps_handler.py --external-deps eventhandler:libeventhandler ces_standard:cesfwk_innerkits hiviewdfx_hilog_native:libhilog --parts-src-flag-file build_configs/parts_src_flag.json --external-deps-temp-file gen/kaihong/communication/kh_iotsdk/src/bonding/kh_iotsdk__bondingtest_external_deps_temp.json --sdk-base-dir ../../sdk/ohos-arm --sdk-dir-name sdk/ohos-arm --current-toolchain //build/toolchain/ohos:ohos_clang_arm --innerkits-adapter-info-file ../../build/ohos/inner_kits_adapter.json [OHOS INFO] Returned 1 and printed out: [OHOS INFO] [OHOS INFO] file '../../sdk/ohos-arm/ces_standard/sdk_info.json' doesn't exist. [OHOS INFO] [OHOS INFO] stderr: [OHOS INFO] [OHOS INFO] Traceback (most recent call last): [OHOS INFO] File "/home/huangjianli/kh3.2/build/templates/common/external_deps_handler.py", line 248, in <module> [OHOS INFO] sys.exit(main()) [OHOS INFO] File "/home/huangjianli/kh3.2/build/templates/common/external_deps_handler.py", line 214, in main [OHOS INFO] sdk_module_info, adapted_ok = _get_external_module_from_sdk( [OHOS INFO] File "/home/huangjianli/kh3.2/build/templates/common/external_deps_handler.py", line 73, in _get_external_module_from_sdk [OHOS INFO] raise Exception("part '{}' doesn't exist in sdk modules.".format( [OHOS INFO] Exception: part 'ces_standard' doesn't exist in sdk modules. [OHOS INFO] [OHOS INFO] See //kaihong/communication/kh_iotsdk/src/bonding/BUILD.gn:16:1: whence it was called. [OHOS INFO] ohos_executable("bondingtest") { [OHOS INFO] ^------------------------------- [OHOS INFO] See //kaihong/communication/kh_iotsdk/BUILD.gn:123:7: which caused the file to be included. [OHOS INFO] "//kaihong/communication/kh_iotsdk/src/bonding:bondingtest", [OHOS INFO] ^----------------------------------------------------------
06-08
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值