ARTS
Mon, 17 Dec 2018 09:58:31 +0000
- A (Algotithm) 至少做一个leetcode的算法题
- R (Review) 阅读并点评一篇英文的技术文章
- T (Tip) 学习一个技术技巧
- S (Share) 分享一篇有观点和思考的技术文章
每周一次,坚持一年
Algorithm
Description Longest Common Prefix
Solution
/**
* @param {string[]} strs
* @return {string}
*/
var longestCommonPrefix = function(strs) {
var prefix = strs[0];
var strIndex = 0;
var res;
while(strIndex < strs.length) {
res = strs[strIndex].match('^' + prefix);
if (!res) {
prefix = prefix.slice(0, -1);
} else {
strIndex++;
}
}
return (res && res[0]) || '';
};
var arr = ["flower","flow","flight"];
console.log(arr, longestCommonPrefix(arr), 'fl');
arr = ["dog","racecar","car"];
console.log(arr, longestCommonPrefix(arr), '');
arr = ["flower","flow","flight"];
console.log(arr, longestCommonPrefix(arr), 'fl');
arr = ["flower"];
console.log(arr, longestCommonPrefix(arr), 'flower');
Review
Data Classes https://kotlinlang.org/docs/reference/data-classes.html#data-classes
定义 data class
data class User(val name: String, val age: Int)
意味着
public class User {
private final String name;
private final Int age;
public User(String name, Int age) {
this.name = name;
this.age = age;
}
public String getName() {
return name;
}
public Int getAge() {
return age;
}
@Override
public boolean equals(Object other) {
...
}
@Override
public int hashCode() {
...
}
@Override
public String toString() {
...
}
}
Tip
UGC / PGC
UGC(User-generated Content,用户生产内容) PGC(Professionally-generated Content,专业生产内容)
Share
未完待续。。。
blog comments powered by Disqus