首页 > 代码库 > newwork setup
newwork setup
#-*-coding:utf-8-*-########################################################################## Copyright (C) 2017 All rights reserved.# # FileName:GetLongestSubString.py# Creator: x‘x‘x@xxx.com# Time:06/02/2017# Description:## Updates:###########################################################################!/usr/bin/python# please add your code here!import re;import sys;import time;def PrintUsage(): sys.stderr.write("program [IN]\n"); sys.exit(1);class Solution: def GetLongestSubString(self,s1,s2): ‘‘‘ compute longest substring of input string s1 and s2 ‘‘‘ maxLen = 0; endIndex = 0; print("s1="+s1); print("s2="+s2); if ( len(s1) == 0 or len(s2) == 0 ): return ""; table=[[] for i in range(len(s1))]; for i in range(len(table)): table[i]=[0 for j in range(len(s2))]; for i in range(0,len(s1)): for j in range(0,len(s2)): if ( i == 0 or j == 0 ): if ( s1[i]==s2[j] ): table[i][j] = 1; if ( table[i][j] > maxLen ): maxLen = table[i][j]; endIndex = i; else: if ( s1[i]==s2[j] ): table[i][j] = table[i-1][j-1]+1; if (table[i][j] > maxLen): maxLen = table[i][j]; endIndex = i; print(table); return s1[endIndex-maxLen+1:endIndex+1];if (__name__=="__main__"): if (len(sys.argv) != 1): PrintUsage(); sys.exit(1); starttime = time.clock(); s1="gcdef"; s2="abcdef"; sol = Solution(); print(sol.GetLongestSubString(s1,s2)); endtime = time.clock(); interval = endtime - starttime; sys.stderr.write("%s has finished congratulations!\n"%str(sys.argv[0])); sys.stderr.write("time elapse:%f\n"%interval);
newwork setup
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。