原创 面試常見算法題---二分查找(遞歸) python
注意判斷找不到num的情況,另外移動的時候可以多移動一位,查找速度更快。class Solution(): def two_part_search(self, list, num, i, j): while i <
原创 python實現 LeetCode35——Search Insert Position
自己開始寫的代碼,不過因爲要多判斷一次第一個數字,所以感覺不是很整潔,不過也通過了。class Solution(object): def searchInsert(self, nums, target): sta
原创 面試常見算法題---快速排序python
利用遞歸進行快速排序class Solution(): def quicksort(self, list, low, high): if low >= high: return list
原创 面試常見算法題---堆排序python
堆排序注意判斷最後一個根節點只有左節點,沒有右節點的情況。class Solution(): def heap_sort(self, heap): root = (len(heap)-2)//2 f
原创 python實現 LeetCode40—— Combination Sum II
和上一個題很像,但是每個數字只能使用一次。class Solution(object): def combinationSum2(self, candidates, target): self.result=[]
原创 python實現 LeetCode34——Search for a Range
二分法找到target的位置,再判斷前後的位置class Solution(object): def searchRange(self, nums, target): start=0 end=len
原创 python實現 LeetCode33——Search in Rotated Sort
Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 migh
原创 python實現 LeetCode43——Multiply Strings
先反序,在統計位數,取模是本位數,除十是進位的數。class Solution(object): def multiply(self, num1, num2): num1=num1[::-1] nu
原创 python實現 LeetCode31——Next Permutation
Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.
原创 面試常見算法題---二分查找 python
注意判斷找不到num的情況,另外移動的時候可以多移動一位,查找速度更快。class Solution(): def seek(self, s, target): i = 0 j = len(s)-1
原创 kaggle Titanic 數據可視化
參考文章https://zhuanlan.zhihu.com/p/27550334在20世紀初,由英國白星輪船公司耗資7500萬英鎊打造的當時世界上最大的豪華客輪“泰坦尼克”號,曾被稱作爲“永不沉沒的船”和“夢幻之船”這艘豪輪在她的處女之
原创 python實現 LeetCode39——Combination Sum
利用遞歸的方式求得和爲定值的數,如果目標值小於0,肯定不是解,就break。class Solution(object): def combinationSum(self, candidates, target):
原创 斯坦福coursera作業題神經網絡訓練數字識別Backpropagation
神經網絡的後向傳播算法的主要思路是: 1.生成隨機的係數矩陣theta1和theta2,並根據前向傳播算法計算得出每個例子爲每個數字的概率,在本題中,也就是5000個10*1的矩陣 2.再根據已知答案得出真實值和計算值得差值,在通過公式
原创 斯坦福coursera作業題神經網絡訓練數字識別Feedforward Propagation and Prediction
神經網絡前饋實現,主要是根據下圖 def nnCostFunction(theta1,theta2,num_labels, x, y, lamda): m=len(x) one1=np.ones(m) a1=n
原创 python實現 LeetCode36——Count and Say
count代表這個這個數一共有幾個,利用count再加上這個位置的數,最終得到最後的結果class Solution(object): def countAndSay(self, n): string='1'