Created
June 29, 2015 15:02
-
-
Save itsreallynick/54c84ec8a4e4cb4e9bc7 to your computer and use it in GitHub Desktop.
Network Analysis Scripts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# USAGE: ./longestSubstring.sh 'abcdefghi' 'abcdeghi' | |
word1="$1" | |
word2="$2" | |
if [ ${#word1} -lt ${#word2} ] | |
then | |
word1="$2" | |
word2="$1" | |
fi | |
for ((i=${#word2}; i>0; i--)); do | |
for ((j=0; j<=${#word2}-i; j++)); do | |
if [[ $word1 =~ ${word2:j:i} ]] | |
then | |
echo ${word2:j:i} | |
exit | |
fi | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment