lyChai1995 / myobj

1 stars 0 forks source link

ARTS 第七周(2019.10.28-2019.11.03) #8

Open lyChai1995 opened 4 years ago

lyChai1995 commented 4 years ago

ARTS 第八周(2019.10.28-2019.11.03)

  • 编写一个函数来查找字符串数组中的最长公共前缀。
  • Review 构建大型 Vue.js 项目的10条建议
  • Tip 让你的组件千变万化,Vue slot 剖玄析微
  • Share 为你重新系统梳理下, Web 体验优化中和图有关的那些事

Algorithm 编写一个函数来查找字符串数组中的最长公共前缀。

编写一个函数来查找字符串数组中的最长公共前缀。 如果不存在公共前缀,返回空字符串 ""。

代码

public String longestCommonPrefix3(String[] strs) {
  if(strs.length == 0) {
       return "";
   }
   String result = strs[0];
   for(int i=0; i<strs.length; i++) {
      while(strs[i].indexOf(result) != 0) {
          result = result.substring(0, result.length()-1);
           if(result.length() == 0) {
              return "";
          }
     }
  }
 return result;
}

对str[0]按字符遍历,与其他字符串依次比较对应位置上的字符,并记录查找位置,如果找到不相>等或者对应字符串的长度到了限制,就找到了。 image

https://leetcode-cn.com/explore/interview/card/top-interview-questions-easy/5/strings/40/

Review:构建大型 Vue.js 项目的10条建议

https://juejin.im/post/5dcbd5f66fb9a06061527cb9

Tip: 让你的组件千变万化,Vue slot 剖玄析微

https://juejin.im/post/5dcbc236e51d451be55dde44 ◎ 默认插槽 子组件编写:在组件中添加 元素,来确定渲染的位置。 父组件编写:任何没有被包裹在带有 v-slot 的