Coding Practice

本章主要学习如何透过演算法学习训练思考


Palindrome BigO(n)

检查是否reverse也是相同的
EX: anna = anna

function Palindrome(str){
    let left = 0
    let right = str.length -1
    
    while(left <= right){
        if(str[left] === str[right]){
            left++
            right--
        }else{
            return false
        }
    }return true
}
console.log(Palindrome('hcco')) //false

Subsequence

检查是否为子序列

function subsequence(str1, str2){ //str1为原始序列, str2为子序列
    if(str1.length == 0 ){
        return true
    }
    let pointer1 = 0 //设置两个指标,逐一比对
    let pointer2 = 0

    while(str2.length > pointer2){
        if(str1[pointer1] == str2[pointer2]){ //若str1 == str2 str1[pointer] ++ 继续比对
            pointer1++
        }
        if(pointer1 >= str1.length){
            return true //如果pointer已经 == str1长度 代表都符合 即回传true
        }
        pointer2++ //每次执行都要比对str2[pointer] 所以++
    }return false ///若都不符合即回传false
}
console.log(subsequence("hello", "hssello")) //true
console.log(subsequence("hello", "ehllo"))  //false

<<:  Mac OS用FortiClient无法连线

>>:  Recursion

[Day26] 第二十六课 Azure巢状虚拟化-1 [进阶]

先前有做过巢状虚拟化的建置,趁这次参加铁人赛的机会把它分享出来 先讲结论 巢状虚拟化的效能不会太好,...

[DAY 04] 阿桐意面

阿桐意面 地点:台南市盐水区信义路4-6号 时间:8:00~19:30 来盐水怎麽可能不吃意面呢~ ...

Day 3:Kotlin 程序设计基础入门 (2)

本篇文章同步发表在 HKT 线上教室 部落格,线上影音教学课程已上架至 Udemy 和 Youtu...

Day 19. UI 设计软件- Figma 简介与优势

前二篇解释了 GUI Design 阶段的重点,也提到此时花费设计师的工时相当可观。功欲善其事,必先...

IOS Swift Protocol经典范例

protocol 范例快速纪录 protocol transferMoney { func give...