Introduction

• Algorithm - Learning Algorithm
• Review - Learning English
• Tip - Learning Techniques
• Share - Learning Influence

Let’s do it!!!

Algorithm

1. Description
• Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000.

Example 1: Input: “babad” Output: “bab” Note: “aba” is also a valid answer. Example 2: Input: “cbbd” Output: “bb”

2. Solution Brute Force

package com.silence.arts.leetcode.first;

/**
* <br>
* <b>Function：</b><br>
* <b>Author：</b>@author Silence<br>
* <b>Date：</b>2018-07-12 22:50<br>
* <b>Desc：</b>无<br>
*/
public class LongestPalindrome_5 {

/**
* Brute Force
* 1. 找出所有的子串依次遍历判断是否是回文字符串
* 2. 如果是回文串，并且长度比len大，则更新结果
*
* 1. find all substrings and find the longest Palindromic substring
* 2. while k == end (odd numbers) or k + 1 == end (even numbers) means the substring is Palindromic substring
*
* @param s
* @return
*/
public static String longestPalindrome(String s) {
String result = s.substring(0, 1);
int len = 0;
long start = System.currentTimeMillis();
for (int i = 0; i < s.length(); i++) {
for (int j = i + 1; j <= s.length(); j++) {
String substring = s.substring(i, j);
for (int k = 0; k < substring.length(); k++) {
int end = substring.length() - k - 1;
if (substring.length() >= len && substring.charAt(k) == substring.charAt(end)) {
if (((k == end) || (k + 1 == end))) {
if (substring.length() > len) {
len = Math.max(len, substring.length());
result = substring;
}
}
}else {
break;
}
}
}
}
System.out.println((System.currentTimeMillis() - start));
return result;
}

public static void main(String[] args) {
}

}

Think

1. Firstly, find out all of substrings
2. Secondly, Traversing the Characters of substring from both side to compare if they are same, such as substring[begin] == substring[end]
3. if so, begin += 1, end -= 1 until begin == end or begin = end -1

1. 先找出所有的子串
2. 遍历所有子串，从子串的两边开始遍历，如果substring[begin] == substring[end]begin += 1,end -= 1直到begin==end，或者begin + 1 end时结束，再判断substring的长度是否大于len，

Review

10 Tricks to Appear Smart During Meetings

Here are 10 tricks:

• Draw a Venn diagram
• Translate percentage metrics into fractions
• Encourage everyone to “take a step back”
• Nod continuously while pretending to take notes
• Repeat the last thing the engineer said, but very very slowly
• Ask “Will this scale?” no matter what it is
• Pace around the room
• Ask the presenter to go back a slide
• Step out for a phone call
• Make fun of yourself

To be honest, I don’t agree with the author about the tricks not all of them. It’s very impolite! Why do you need to pretend to take notes? Just take notes.! There are always we can learn something from others. Perhaps it’s because we have different cultures.

Tips

1. vim
• 命令模式 u撤回上一步操作
• vim ~/..vimrc 设置个性化操作 如：set nu设置显示行号