筆記
我用死薪水輕鬆理財賺千萬
- 335
- 0
筆記
筆記
景氣循環投資筆記
題目給定一個已排序好的linked list,要求將所有重複的node皆刪除,使得每個元素均只出現一次。
Given a sorted linked list, delete all duplicates such that each element appear only once.
爬一個階梯。到頂端總共需走n階,每次你都可以選擇爬1階或2階,問有幾種不同的方法可以爬到階梯頂端?
You are climbing a stair case. It takes n steps to reach to the top.
Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?
Note: Given n will be a positive integer.
給定兩個二位元字串,回傳兩個二位元總和並以二位元字串表示。
Given two binary strings, return their sum (also a binary string).
The input strings are both non-empty and contains only characters 1
or 0
.
題目給定一個整數陣列,要求找到一個連續的子陣列,這個子陣列的和是所有子陣列中最大的,並回傳該總和值。
Given an integer array nums
, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum.
給定一個數值不重複的已排序陣列和目標值,題目要求找出該目標值在這個陣列中的索引位置;若找不到則回傳插入數值的正確排序位置。
Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.
此題要求將輸入的已排序陣列移除重複的項目,必須在同一陣列下操作,最後回傳陣列之長度。
Given a sorted array nums, remove the duplicates in-place such that each element appear only once and return the new length.
回傳兩個已經排序過的linked list的合併,僅能使用原有的linked list回傳。
Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.
所有類別都相依於抽象,而非具體實作。
多個專用介面優於一個通用介面
子型別必須可以被替換成它的基底型別
軟體實體(類別、模組、函式)應能開放擴充但封閉修改
找出陣列裡元素的重複字元,沒有共同重複字元則回傳空字串。
Write a function to find the longest common prefix string amongst an array of strings.
If there is no common prefix, return an empty string ""
.
在一組陣列中找出兩個數,其加總恰等於給定值。 每個數不能被重複使用,且必剛好只有一個解。
Given an array of integers, return indices of the two numbers such that they add up to a specific target.
You may assume that each input would have exactly one solution, and you may not use the same element twice.
一個類別應該只有一個改變的理由!
SRP的主要精神是提高內聚力,高內聚力意味著你只能想到一個理由去改變它!
內聚力與耦合力 Cohesion & Coupling
物件導向設計 SOLID 設計原則
1.創建者模式: 抽象工廠(abstract factory)、工廠方法(factory method)、建造者(builder)、原型(prototype)、單例(singleton)
2.結構型模式: 轉接器(adapter)、橋接(bridge)、合成(composite)、代理(proxy) 等等...
3.行為型模式: 中介者(mediator)、觀察者(observer)、責任練(chain of responsibility) 等等...