ARTS-20180630

297 阅读1分钟

Algorithm

题目 判断子序列

实现

class Solution {
   
   // 最初始,最容易想到的: 依次匹配子短字符串中的每一个字符
   static func isSubsequence(_ s: String, _ t: String) -> Bool {
       guard s.count > 0 else {
           return true
       }
       var matchCount = 0
       var sIndex = s.startIndex
       var tIndex = t.startIndex

       while tIndex != t.endIndex {
           if(s[sIndex] == t[tIndex]){
               matchCount = matchCount + 1
               sIndex = s.index(sIndex, offsetBy: 1)
           }
           tIndex = t.index(tIndex, offsetBy: 1)
           if matchCount == s.count {
               return true
           }
       }
       return false
   }
}

得到

  • swift的字符串的用法需要熟悉。设计和C语言的理念不一样,导致实现的时候查了老半天语法使用。
  • 算法采用的是最简单粗暴的方式。应该会有更好的方式。

Review

文章:Taming Great Complexity: MVVM, Coordinators and RxSwift

  • 提供了一种页面转场的方法:Coordinators。主要是要配合MVVM的架构。在MVVM的架构中,页面跳转的逻辑放在View中也不对,因为对于MVVM,View应该只有展示没有跳转逻辑。放在VM中也不好,因为跳转还是要UIKit的东西。所以单独抽出来一个结构,做页面跳转。
  • Coordinators 的方式让跳转的逻辑独立出来了。带来的好处就是架构清晰,模块化,扩展性都很好。同时,也引入了复杂性。毕竟又多了一个东西,还有组装过程。实际项目过程中,还是需要综合考虑。

Technique

买了极客时间的React课程,不知道算不算?

Share

http://khanlou.com/2015/10/coordinators-redux/