Open lyChai1995 opened 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]按字符遍历,与其他字符串依次比较对应位置上的字符,并记录查找位置,如果找到不相>等或者对应字符串的长度到了限制,就找到了。
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 的 中的内容都会被视为默认插槽的内容。>当子组件只有默认插槽时, 标签可以直接用在组件上,也就是独占默认插槽的写法 ◎ 具名插槽 子组件编写:当需要使用多个插槽时,为 元素添加 name 属性,来区分不同的插槽,当不>填写 name 时,默认为 default 默认插槽。 父组件编写: 标签中添加 v-slot:xxx 或者 #xxx 属性的内容, # 代表插槽的缩写 ◎ 作用域插槽 子组件编写:有时让父组件能访问到子组件中的数据是很有用的,我们可以将绑定在 元素>上的特性称为插槽 Prop ,当然也可以传递一些 Function。 父组件编写:被绑定的属性的集合对象,在父元素中会被 v-slot:xxx="slotProps" 或者 >#xxx="slotProps" 接收,xxx 代表具名插槽的 name ,slotProps 为子组件传递的数据对象,可以重>命名。 ◎ 其他拓展
- 解构插槽 prop 可以重命名,例如:v-slot="{ user: person }" 将 user 对象重命名为 person 使用。
- 解构插槽 prop 可以赋值默认值,例如:v-slot="{ user = { name: 'Guest' } }" 给属性添加自定义后>备内容。
- 动态插槽命名,例如:v-slot:[dynamicSlotName] ,支持命名变量定义。
Share: 为你重新系统梳理下, Web 体验优化中和图有关的那些事(万字长文)