2018年12月30日星期日

[LeetCode] 5. Longest Palindromic Substring

https://leetcode.com/problems/longest-palindromic-substring/

解法一:使用了在水中的鱼的博客看到的第一种思路(http://fisherlei.blogspot.com/2012/12/leetcode-longest-palindromic-substring.html),对于任意一个index,分别向前、向后查找可能的palindrome。因为palindrome有“aba”和“abba”两种形式,所以还需要照顾到当s[index]==s[index + 1]这种情况。时间复杂度 O(n^2)。代码如下:


明天再想想其他解法  \(▔▽▔)/

2018年4月2日星期一

Bash 的基本语法规则

1. 函数传参

#!/bin/bash

test_function() {
    echo $1 $2
}
test_function "hello" "world"

Result:
~$ ./example.sh 
hello world


2. 分割字符串

#!/bin/bash

LINE="test_name,test_address,test_phone_number"
name=$(echo $LINE | cut -d ',' -f 1)
address=$(echo $LINE | cut -d ',' -f 2)
phone_number=$(echo $LINE | cut -d ',' -f 3)
echo $name
echo $address
echo $phone_number

Result:
~$ ./example.sh 
test_name
test_address
test_phone_number


3. 读取文件

#!/bin/bash

i=0
SPACE=" "
while read line
do
    echo $i $SPACE $line
    i=$((i+1))
done < test.txt

Result:
~$ cat test.txt
hahaha
haha
ha
~$ ./example.sh 
0 hahaha
1 haha
2 ha


4. 正则表达式匹配

#!/bin/bash

LINE="This is a test string. Let's see if the UUID will be matched: ea77b80d-d17f-476a-b55f-916423d02dcc. Hahaha!"
uuid=$(echo $LINE | grep -E -o '[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}')
echo $uuid

Result:
~$ ./example.sh 
ea77b80d-d17f-476a-b55f-916423d02dcc











2018年4月1日星期日

Hazelcast 学习笔记

~$ ls /Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home


(3) Exception in thread "main" com.hazelcast.license.exception.InvalidLicenseException: License Key not configured!

(4) Replication vs. partitioning

(5) Most common use case: being a cache on top of a database

(6) Hazelcast has two modes: embedded mode and client-server mode