這篇筆記下實作 String.prototype.toLowerCase, String.prototype.endsWith 的過程(僅會實作出最基本的功能)
課程相關資訊
[連結]:https://lidemy.com/p/alg101-leetcode
Course 80 ~ Course 81 (全部一共有 106 Courses)
請注意:本系列文章為個人對應課程的消化吸收後,所整理出來的內容。換言之,並不一定會包含全部的課程內容,也有可能會添加其他資源來說明。
內容
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
// String.toLowerCase function solve(lines){ console.log(toLowerCase(lines[0])) } function toLowerCase(str) { let result = "" for(let i=0; i<str.length;i++){ if(str[i]>="A" && str[i]<="Z"){ let code = str.charCodeAt(i) result += String.fromCharCode(code + 32) }else{ result += str[i] } } return result } // String.endsWith function solve(lines){ console.log(endsWith(lines[0],lines[1])) } function endsWith(str, searchString) { if(searchString.length > str.length) return false let searchStringIndex = searchString.length - 1 let strIndex = str.length - 1 while(searchStringIndex >= 0){ if(searchString[searchStringIndex] !== str[strIndex]){ return false } searchStringIndex-- strIndex-- } return true } |
相關文章
★全文分享★ [筆記] ALG101 – 先別急著寫 LeetCode22
最後一個為有效率的求取最大整數連續和的解法,加上一些補充資料。課程相關資
★全文分享★ [筆記] ALG101 – 先別急著寫 LeetCode21
先前做過的簡單排序法、搜尋數字,改用較為有效率進行的方法來操作。課程相關
★全文分享★ [筆記] ALG101 – 先別急著寫 LeetCode20
接著來練習用迴圈的方法來解決陣列最短距離、Two Sum 和逆序數對,先不考慮 big O
★全文分享★ [筆記] ALG101 – 先別急著寫 LeetCode19
接下來練習搜尋數字和連續整數和,先從直覺但不一定有效率的方法開始。課程相
★全文分享★ [筆記] ALG101 – 先別急著寫 LeetCode18
先求有,再求好。這個部分要稍微帶到演算法的時間和空間複雜度的概念,加上一
★全文分享★ [筆記] ALG101 – 先別急著寫 LeetCode17
接下來的兩題,其核心概念為 N 進位數和多重的條件判斷,才能印出正確的值。課
★全文分享★ [筆記] ALG101 – 先別急著寫 LeetCode16
國中程度競賽題的實作,其實難度本身不一定高,但是題目外衣包裝的很精美,你
★全文分享★ [筆記] ALG101 – 先別急著寫 LeetCode15
接著要來進行一些國中程度競賽題的挑戰,讓你跳脫既定的思考模式,看一下這些
★全文分享★ [筆記] ALG101 – 先別急著寫 LeetCode14
這篇筆記下實作 String.prototype.padEnd, String.prototype.slice 的過程(僅會實作出最基本的
★全文分享★ [筆記] ALG101 – 先別急著寫 LeetCode12
這篇筆記下實作 Array.prototype.fill, Array.prototype.join, String.trim 的過程(僅會實作出最
★全文分享★ [筆記] ALG101 – 先別急著寫 LeetCode11
更多的練習是必要的,這篇筆記下實作 Array.prototype.reverse, Array.prototype.filter, Array.pro
★全文分享★ [筆記] ALG101 – 先別急著寫 LeetCode10
雖說 JavaScript 已經有不少的內建函式,例如 Array.prototype.map、Array.prototype.lastIndexOf ..
★全文分享★ [筆記] ALG101 – 先別急著寫 LeetCode9
到了經典題目的最後了,來練習求出最近點對、凱薩加密和圈圈叉叉小遊戲。課程
★全文分享★ [筆記] ALG101 – 先別急著寫 LeetCode8
繼續更多的練習,來進行加減乘除、迴文判斷、完全平方和以及平面距離計算。課
★全文分享★ [筆記] ALG101 – 先別急著寫 LeetCode7
在盡可能不使用內建函式的情況下,來判斷等比數列、信用卡號驗證以及你的生命
★全文分享★ [筆記] ALG101 – 先別急著寫 LeetCode6
經歷過前幾個單元的準備,總算是要進入寫一些經典題目的部分了,像是等差數列
★全文分享★ [筆記] ALG101 – 先別急著寫 LeetCode5
這個階段透過實作練習,讓你可以了解到撰寫迴圈、判斷式和找規律時,先將問題
★全文分享★ [筆記] ALG101 – 先別急著寫 LeetCode4
在實際解決題目之前,要先理解平台修改的方式,可分為 “函式輸出” 和 “標準輸出
★全文分享★ [筆記] ALG101 – 先別急著寫 LeetCode3
講述空間、時間和範圍型態的限制外,以及更多的範例來讓你學會怎樣看懂程式。
★全文分享★ [筆記] ALG101 – 先別急著寫 LeetCode2
除了撰寫虛擬碼外,另外一件重要的環節就是「學習如何像電腦一樣思考」。換言
★全文分享★ [筆記] Lidemy 鋰學院 – 先別急著寫 LeetCode – 1
近年來想要進行程式人員相關的面試前,上 LeetCode 刷題成為了一門顯學。不過對於