diff --git a/C++/ClassDemo.cpp b/C++/ClassDemo.cpp new file mode 100644 index 0000000..f437125 --- /dev/null +++ b/C++/ClassDemo.cpp @@ -0,0 +1,43 @@ +#include +using namespace std; + +class Animal +{ + protected: + char name[4] = "0"; + int age = 0; + int height = 0; + double weight = 0; + + public: + Animal(){} + ~Animal(){} + virtual void Walk() = 0; + virtual void Eat() = 0; + virtual void Sleep() = 0; +}; + +class Dog: public Animal +{ + public: + virtual void Walk(){}; + virtual void Eat(){}; + virtual void Sleep(){}; +}; + +class Cat: public Animal +{ + public: + virtual void Walk(){} + virtual void Eat(){} + virtual void Sleep(){} +}; + +int main() +{ + Animal *animal; + Dog dog; + animal = &dog; + animal->Walk(); + return 0; +} \ No newline at end of file diff --git a/C++/InsertSort.cpp b/C++/InsertSort.cpp new file mode 100644 index 0000000..550ed76 --- /dev/null +++ b/C++/InsertSort.cpp @@ -0,0 +1,25 @@ +#include +#include +using namespace std; + +void InsertSort(vector &num){ + for(int i=1; i0 && num[position-1]>cur){ + num[position] = num[position-1]; + position--; + } + num[position] = cur; + } +} + +int main() +{ + int a[9] = {54,26,93,17,77,31,44,55,20}; + vector num(a, a+9); + InsertSort(num); + for(int i=0;i<=num.size()-1;i++) + cout<array[j+1]: + array[j],array[j+1] = array[j+1],array[j] + return array + +def modiBuddleSort2(array): + flag = True + i = 0 + while i!=len(array) and flag: + flag = False + for j in range(len(array)-1-i): + if array[j]>array[j+1]: + array[j],array[j+1] = array[j+1],array[j] + flag = True + i+=1 + return array + +print(modiBuddleSort2(alist)) \ No newline at end of file diff --git a/InsertionSort.py b/Sort/InsertionSort.py similarity index 68% rename from InsertionSort.py rename to Sort/InsertionSort.py index 6e47d81..192f128 100644 --- a/InsertionSort.py +++ b/Sort/InsertionSort.py @@ -1,3 +1,5 @@ +# 时间复杂度 最好是O(n) 最差是O(n^2) + def insertionSort(alist): for key, item in enumerate(alist): index = key @@ -22,4 +24,15 @@ def insertionSort2(alist): return alist +def insertSort3(array): + for i in range(1,len(array)): + cur = array[i] + index = i + + while index>0 and array[index-1]>cur: + array[index-1] = array[index] + index-=1 + array[index] = cur + return array + print(insertionSort2(alist)) diff --git a/QuickSort.py b/Sort/QuickSort.py similarity index 72% rename from QuickSort.py rename to Sort/QuickSort.py index 59b0972..d6d0824 100644 --- a/QuickSort.py +++ b/Sort/QuickSort.py @@ -30,6 +30,27 @@ def partition(alist, first, last): alist[rightmark], alist[first] = alist[first], alist[rightmark] return rightmark +def quickSort2(array,start,end): + if start<=end: + return + k = array[start] + left = start + right = end + + while leftk: + right-=1 + array[left],array[right] = array[right],array[left] + + while leftarray[j]: + array[i],array[j] = array[j],array[i] + return array + +def modiselectionSort(array): + for i in range(len(array)): + index = i + for j in range(i,len(array)): + if array[i]>array[j]: + index = j + array[i],array[index] = array[index],array[i] + +alist = [54,26,93,17,77,31,44,55,20] +print(selectionSort(alist)) \ No newline at end of file diff --git "a/Target Offer/\350\260\203\346\225\264\346\225\260\347\273\204\351\241\272\345\272\217\344\275\277\345\245\207\346\225\260\344\275\215\344\272\216\345\201\266\346\225\260\345\211\215\351\235\242.py" "b/Target Offer/10\350\260\203\346\225\264\346\225\260\347\273\204\351\241\272\345\272\217\344\275\277\345\245\207\346\225\260\344\275\215\344\272\216\345\201\266\346\225\260\345\211\215\351\235\242.py" similarity index 100% rename from "Target Offer/\350\260\203\346\225\264\346\225\260\347\273\204\351\241\272\345\272\217\344\275\277\345\245\207\346\225\260\344\275\215\344\272\216\345\201\266\346\225\260\345\211\215\351\235\242.py" rename to "Target Offer/10\350\260\203\346\225\264\346\225\260\347\273\204\351\241\272\345\272\217\344\275\277\345\245\207\346\225\260\344\275\215\344\272\216\345\201\266\346\225\260\345\211\215\351\235\242.py" diff --git "a/Target Offer/\351\223\276\350\241\250\344\270\255\345\200\222\346\225\260\347\254\254k\344\270\252\347\273\223\347\202\271.py" "b/Target Offer/11\351\223\276\350\241\250\344\270\255\345\200\222\346\225\260\347\254\254k\344\270\252\347\273\223\347\202\271.py" similarity index 100% rename from "Target Offer/\351\223\276\350\241\250\344\270\255\345\200\222\346\225\260\347\254\254k\344\270\252\347\273\223\347\202\271.py" rename to "Target Offer/11\351\223\276\350\241\250\344\270\255\345\200\222\346\225\260\347\254\254k\344\270\252\347\273\223\347\202\271.py" diff --git "a/Target Offer/\345\217\215\350\275\254\351\223\276\350\241\250.py" "b/Target Offer/12\345\217\215\350\275\254\351\223\276\350\241\250.py" similarity index 75% rename from "Target Offer/\345\217\215\350\275\254\351\223\276\350\241\250.py" rename to "Target Offer/12\345\217\215\350\275\254\351\223\276\350\241\250.py" index c8e2bb8..0af2a15 100644 --- "a/Target Offer/\345\217\215\350\275\254\351\223\276\350\241\250.py" +++ "b/Target Offer/12\345\217\215\350\275\254\351\223\276\350\241\250.py" @@ -9,6 +9,22 @@ def __init__(self, x): self.val = x self.next = None class Solution: + + def ReverseList(self, pHead): + # write code here + if not pHead: + return + elif not pHead.next: + return pHead + pre = None + nextt = None + while pHead: + nextt = pHead.next + pHead.next = pre + pre = pHead + pHead = nextt + return pre + # 返回ListNode def ReverseList(self, pHead): pReversedHead = None diff --git "a/Target Offer/\345\220\210\345\271\266\344\270\244\344\270\252\346\216\222\345\272\217\347\232\204\351\223\276\350\241\250.py" "b/Target Offer/13\345\220\210\345\271\266\344\270\244\344\270\252\346\216\222\345\272\217\347\232\204\351\223\276\350\241\250.py" similarity index 100% rename from "Target Offer/\345\220\210\345\271\266\344\270\244\344\270\252\346\216\222\345\272\217\347\232\204\351\223\276\350\241\250.py" rename to "Target Offer/13\345\220\210\345\271\266\344\270\244\344\270\252\346\216\222\345\272\217\347\232\204\351\223\276\350\241\250.py" diff --git "a/Target Offer/\346\240\221\347\232\204\345\255\220\347\273\223\346\236\204.py" "b/Target Offer/14\346\240\221\347\232\204\345\255\220\347\273\223\346\236\204.py" similarity index 100% rename from "Target Offer/\346\240\221\347\232\204\345\255\220\347\273\223\346\236\204.py" rename to "Target Offer/14\346\240\221\347\232\204\345\255\220\347\273\223\346\236\204.py" diff --git "a/Target Offer/\344\272\214\345\217\211\346\240\221\347\232\204\351\225\234\345\203\217.py" "b/Target Offer/15\344\272\214\345\217\211\346\240\221\347\232\204\351\225\234\345\203\217.py" similarity index 100% rename from "Target Offer/\344\272\214\345\217\211\346\240\221\347\232\204\351\225\234\345\203\217.py" rename to "Target Offer/15\344\272\214\345\217\211\346\240\221\347\232\204\351\225\234\345\203\217.py" diff --git "a/Target Offer/\351\241\272\346\227\266\351\222\210\346\211\223\345\215\260\347\237\251\351\230\265.py" "b/Target Offer/16\351\241\272\346\227\266\351\222\210\346\211\223\345\215\260\347\237\251\351\230\265.py" similarity index 100% rename from "Target Offer/\351\241\272\346\227\266\351\222\210\346\211\223\345\215\260\347\237\251\351\230\265.py" rename to "Target Offer/16\351\241\272\346\227\266\351\222\210\346\211\223\345\215\260\347\237\251\351\230\265.py" diff --git "a/Target Offer/\345\214\205\345\220\253min\345\207\275\346\225\260\347\232\204\346\240\210.py" "b/Target Offer/17\345\214\205\345\220\253min\345\207\275\346\225\260\347\232\204\346\240\210.py" similarity index 100% rename from "Target Offer/\345\214\205\345\220\253min\345\207\275\346\225\260\347\232\204\346\240\210.py" rename to "Target Offer/17\345\214\205\345\220\253min\345\207\275\346\225\260\347\232\204\346\240\210.py" diff --git "a/Target Offer/\346\240\210\347\232\204\345\216\213\345\205\245\345\274\271\345\207\272\345\272\217\345\210\227.py" "b/Target Offer/18\346\240\210\347\232\204\345\216\213\345\205\245\345\274\271\345\207\272\345\272\217\345\210\227.py" similarity index 76% rename from "Target Offer/\346\240\210\347\232\204\345\216\213\345\205\245\345\274\271\345\207\272\345\272\217\345\210\227.py" rename to "Target Offer/18\346\240\210\347\232\204\345\216\213\345\205\245\345\274\271\345\207\272\345\272\217\345\210\227.py" index 1350125..9d9da61 100644 --- "a/Target Offer/\346\240\210\347\232\204\345\216\213\345\205\245\345\274\271\345\207\272\345\272\217\345\210\227.py" +++ "b/Target Offer/18\346\240\210\347\232\204\345\216\213\345\205\245\345\274\271\345\207\272\345\272\217\345\210\227.py" @@ -44,8 +44,23 @@ def IsPopOrder2(self, pushV, popV): else: return True + def IsPopOrder3(self, pushV, popV): + # write code here + if pushV == [] or popV == []: + return False + stack = [] + for i in pushV: + stack.append(i) + while len(stack) and stack[-1] == popV[0]: + stack.pop() + popV.pop(0) + if len(stack): + return False + else: + return True + pushV = [1, 2, 3, 4, 5] popV = [4, 5, 3, 2, 1] popVF = [4, 5, 2, 1, 3] S = Solution() -print(S.IsPopOrder2(pushV, popVF)) +print(S.IsPopOrder3(pushV, popV)) diff --git "a/Target Offer/\344\273\216\344\270\212\345\276\200\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221.py" "b/Target Offer/19\344\273\216\344\270\212\345\276\200\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221.py" similarity index 100% rename from "Target Offer/\344\273\216\344\270\212\345\276\200\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221.py" rename to "Target Offer/19\344\273\216\344\270\212\345\276\200\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221.py" diff --git "a/Target Offer/\344\272\214\347\273\264\346\225\260\347\273\204\346\237\245\346\211\276.py" "b/Target Offer/1\344\272\214\347\273\264\346\225\260\347\273\204\346\237\245\346\211\276.py" similarity index 90% rename from "Target Offer/\344\272\214\347\273\264\346\225\260\347\273\204\346\237\245\346\211\276.py" rename to "Target Offer/1\344\272\214\347\273\264\346\225\260\347\273\204\346\237\245\346\211\276.py" index 81239fd..ff7b14e 100644 --- "a/Target Offer/\344\272\214\347\273\264\346\225\260\347\273\204\346\237\245\346\211\276.py" +++ "b/Target Offer/1\344\272\214\347\273\264\346\225\260\347\273\204\346\237\245\346\211\276.py" @@ -18,6 +18,21 @@ class Solution: # array 二维列表 + + def easyFind(self,array,target): + row = len(array) + col = len(array[0]) + i=row-1 + j=0 + while j=0: + if targetarray[i][j]: + j-=1 + else: + return True + return False + def Find(self, array, target): # 判断数组是否为空 if array == []: diff --git "a/Target Offer/\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\345\220\216\347\273\255\351\201\215\345\216\206\345\272\217\345\210\227.py" "b/Target Offer/20\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\345\220\216\347\273\255\351\201\215\345\216\206\345\272\217\345\210\227.py" similarity index 99% rename from "Target Offer/\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\345\220\216\347\273\255\351\201\215\345\216\206\345\272\217\345\210\227.py" rename to "Target Offer/20\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\345\220\216\347\273\255\351\201\215\345\216\206\345\272\217\345\210\227.py" index b1533eb..8798c78 100644 --- "a/Target Offer/\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\345\220\216\347\273\255\351\201\215\345\216\206\345\272\217\345\210\227.py" +++ "b/Target Offer/20\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\345\220\216\347\273\255\351\201\215\345\216\206\345\272\217\345\210\227.py" @@ -13,8 +13,10 @@ def VerifySquenceOfBST(self, sequence): root = sequence[-1] length = len(sequence) + if min(sequence) > root or max(sequence) < root: return True + index = 0 # 二叉搜索树的左子树结点小于根节点 ''' diff --git "a/Target Offer/\344\272\214\345\217\211\346\240\221\344\270\255\345\222\214\344\270\272\346\237\220\344\270\200\345\200\274\347\232\204\350\267\257\345\276\204.py" "b/Target Offer/21\344\272\214\345\217\211\346\240\221\344\270\255\345\222\214\344\270\272\346\237\220\344\270\200\345\200\274\347\232\204\350\267\257\345\276\204.py" similarity index 100% rename from "Target Offer/\344\272\214\345\217\211\346\240\221\344\270\255\345\222\214\344\270\272\346\237\220\344\270\200\345\200\274\347\232\204\350\267\257\345\276\204.py" rename to "Target Offer/21\344\272\214\345\217\211\346\240\221\344\270\255\345\222\214\344\270\272\346\237\220\344\270\200\345\200\274\347\232\204\350\267\257\345\276\204.py" diff --git "a/Target Offer/\345\244\215\346\235\202\351\223\276\350\241\250\347\232\204\345\244\215\345\210\266.py" "b/Target Offer/22\345\244\215\346\235\202\351\223\276\350\241\250\347\232\204\345\244\215\345\210\266.py" similarity index 100% rename from "Target Offer/\345\244\215\346\235\202\351\223\276\350\241\250\347\232\204\345\244\215\345\210\266.py" rename to "Target Offer/22\345\244\215\346\235\202\351\223\276\350\241\250\347\232\204\345\244\215\345\210\266.py" diff --git "a/Target Offer/\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\216\345\217\214\345\220\221\351\223\276\350\241\250.py" "b/Target Offer/23\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\216\345\217\214\345\220\221\351\223\276\350\241\250.py" similarity index 100% rename from "Target Offer/\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\216\345\217\214\345\220\221\351\223\276\350\241\250.py" rename to "Target Offer/23\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\216\345\217\214\345\220\221\351\223\276\350\241\250.py" diff --git "a/Target Offer/\345\255\227\347\254\246\344\270\262\347\232\204\346\216\222\345\210\227\345\222\214\347\273\204\345\220\210.py" "b/Target Offer/24\345\255\227\347\254\246\344\270\262\347\232\204\346\216\222\345\210\227\345\222\214\347\273\204\345\220\210.py" similarity index 97% rename from "Target Offer/\345\255\227\347\254\246\344\270\262\347\232\204\346\216\222\345\210\227\345\222\214\347\273\204\345\220\210.py" rename to "Target Offer/24\345\255\227\347\254\246\344\270\262\347\232\204\346\216\222\345\210\227\345\222\214\347\273\204\345\220\210.py" index 7b16f6d..f36535f 100644 --- "a/Target Offer/\345\255\227\347\254\246\344\270\262\347\232\204\346\216\222\345\210\227\345\222\214\347\273\204\345\220\210.py" +++ "b/Target Offer/24\345\255\227\347\254\246\344\270\262\347\232\204\346\216\222\345\210\227\345\222\214\347\273\204\345\220\210.py" @@ -47,6 +47,7 @@ def group(self, ss): return pStr ss = 'acb' +sss = 'aabc' S = Solution() # print(S.Permutation(ss)) -print(S.group(ss)) \ No newline at end of file +print(S.Permutation(sss)) \ No newline at end of file diff --git "a/Target Offer/\346\225\260\347\273\204\344\270\255\345\207\272\347\216\260\346\254\241\346\225\260\350\266\205\350\277\207\344\270\200\345\215\212\347\232\204\346\225\260\345\255\227.py" "b/Target Offer/25\346\225\260\347\273\204\344\270\255\345\207\272\347\216\260\346\254\241\346\225\260\350\266\205\350\277\207\344\270\200\345\215\212\347\232\204\346\225\260\345\255\227.py" similarity index 100% rename from "Target Offer/\346\225\260\347\273\204\344\270\255\345\207\272\347\216\260\346\254\241\346\225\260\350\266\205\350\277\207\344\270\200\345\215\212\347\232\204\346\225\260\345\255\227.py" rename to "Target Offer/25\346\225\260\347\273\204\344\270\255\345\207\272\347\216\260\346\254\241\346\225\260\350\266\205\350\277\207\344\270\200\345\215\212\347\232\204\346\225\260\345\255\227.py" diff --git "a/Target Offer/\346\233\277\346\215\242\347\251\272\346\240\274.py" "b/Target Offer/2\346\233\277\346\215\242\347\251\272\346\240\274.py" similarity index 79% rename from "Target Offer/\346\233\277\346\215\242\347\251\272\346\240\274.py" rename to "Target Offer/2\346\233\277\346\215\242\347\251\272\346\240\274.py" index bd15a41..13b560d 100644 --- "a/Target Offer/\346\233\277\346\215\242\347\251\272\346\240\274.py" +++ "b/Target Offer/2\346\233\277\346\215\242\347\251\272\346\240\274.py" @@ -6,20 +6,27 @@ # -*- coding:utf-8 -*- class Solution: # s 源字符串 - + + def replaceSpaceByList(self, s): + s = list(s) + for i in range(len(s)): + if s[i] == ' ': + s[i] = '%20' + return ''.join(s) + # 使用append一次遍历即可替换 # 由于list的append是O(1)的时间复杂度,除了扩容所导致的时间损耗,该算法复杂度为O(n) def replaceSpaceByAppend(self, s): - string = list(string) - stringReplace = [] - for item in string: - if item == ' ': - stringReplace.append('%') - stringReplace.append('2') - stringReplace.append('0') - else: - stringReplace.append(item) - return "".join(stringReplace) + string = list(s) + stringReplace = [] + for item in string: + if item == ' ': + stringReplace.append('%') + stringReplace.append('2') + stringReplace.append('0') + else: + stringReplace.append(item) + return "".join(stringReplace) # 创建新的字符串进行替换 def replaceSpace1(self, s): @@ -70,3 +77,4 @@ def replaceSpace3(self, s): print(test.replaceSpace1(s)) print(test.replaceSpace2(s)) print(test.replaceSpace3(s)) +print(test.replaceSpaceByList(s)) diff --git "a/Target Offer/\345\217\215\345\220\221\346\211\223\345\215\260\351\223\276\350\241\250.py" "b/Target Offer/3\345\217\215\345\220\221\346\211\223\345\215\260\351\223\276\350\241\250.py" similarity index 93% rename from "Target Offer/\345\217\215\345\220\221\346\211\223\345\215\260\351\223\276\350\241\250.py" rename to "Target Offer/3\345\217\215\345\220\221\346\211\223\345\215\260\351\223\276\350\241\250.py" index ad0a21d..35d3c59 100644 --- "a/Target Offer/\345\217\215\345\220\221\346\211\223\345\215\260\351\223\276\350\241\250.py" +++ "b/Target Offer/3\345\217\215\345\220\221\346\211\223\345\215\260\351\223\276\350\241\250.py" @@ -8,7 +8,7 @@ def __init__(self, x=None): class Solution: def printListFromTailToHead(self, listNode): - if listNode.val == None: + if listNode==None or listNode.val == None: return l = [] head = listNode diff --git "a/Target Offer/\351\207\215\345\273\272\344\272\214\345\217\211\346\240\221.py" "b/Target Offer/4\351\207\215\345\273\272\344\272\214\345\217\211\346\240\221.py" similarity index 80% rename from "Target Offer/\351\207\215\345\273\272\344\272\214\345\217\211\346\240\221.py" rename to "Target Offer/4\351\207\215\345\273\272\344\272\214\345\217\211\346\240\221.py" index dc7f872..8296334 100644 --- "a/Target Offer/\351\207\215\345\273\272\344\272\214\345\217\211\346\240\221.py" +++ "b/Target Offer/4\351\207\215\345\273\272\344\272\214\345\217\211\346\240\221.py" @@ -12,6 +12,18 @@ def __init__(self, x): self.right = None class Solution: # 返回构造的TreeNode根节点 + def reConstructBinaryTree2(self, pre, tin): + if len(pre)==0: + return None + if len(pre)==1: + return pre[0] + # write code here + root = TreeNode(pre[0]) + i = tin.index(pre[0]) + root.left = self.reConstructBinaryTree(pre[1:i+1],tin[:i]) + root.right = self.reConstructBinaryTree(pre[i+1:],tin[i+1:]) + return root + def reConstructBinaryTree(self, pre, tin): # write code here if not pre and not tin: @@ -28,6 +40,7 @@ def reConstructBinaryTree(self, pre, tin): tin = [5, 3, 6, 2, 4, 1] test = Solution() newTree = test.reConstructBinaryTree(pre, tin) +newTree2 = test.reConstructBinaryTree2(pre, tin) # 按层序遍历输出树中某一层的值 def PrintNodeAtLevel(treeNode, level): if not treeNode or level < 0: diff --git "a/Target Offer/\347\224\250\344\270\244\344\270\252\346\240\210\345\256\236\347\216\260\351\230\237\345\210\227.py" "b/Target Offer/5\347\224\250\344\270\244\344\270\252\346\240\210\345\256\236\347\216\260\351\230\237\345\210\227.py" similarity index 100% rename from "Target Offer/\347\224\250\344\270\244\344\270\252\346\240\210\345\256\236\347\216\260\351\230\237\345\210\227.py" rename to "Target Offer/5\347\224\250\344\270\244\344\270\252\346\240\210\345\256\236\347\216\260\351\230\237\345\210\227.py" diff --git "a/Target Offer/\346\227\213\350\275\254\346\225\260\347\273\204\347\232\204\346\234\200\345\260\217\346\225\260\345\255\227.py" "b/Target Offer/6\346\227\213\350\275\254\346\225\260\347\273\204\347\232\204\346\234\200\345\260\217\346\225\260\345\255\227.py" similarity index 98% rename from "Target Offer/\346\227\213\350\275\254\346\225\260\347\273\204\347\232\204\346\234\200\345\260\217\346\225\260\345\255\227.py" rename to "Target Offer/6\346\227\213\350\275\254\346\225\260\347\273\204\347\232\204\346\234\200\345\260\217\346\225\260\345\255\227.py" index a33dbe0..78a26d3 100644 --- "a/Target Offer/\346\227\213\350\275\254\346\225\260\347\273\204\347\232\204\346\234\200\345\260\217\346\225\260\345\255\227.py" +++ "b/Target Offer/6\346\227\213\350\275\254\346\225\260\347\273\204\347\232\204\346\234\200\345\260\217\346\225\260\345\255\227.py" @@ -39,7 +39,7 @@ def minNumberInRotateArray2(self, rotateArray): if rear - front == 1: midIndex = rear break - midIndex = (front + rear) // 2 + midIndex = (front + rear) >> 1 if rotateArray[front] == rotateArray[rear] and rotateArray[front] == rotateArray[midIndex]: return self.MinInOrder(rotateArray, front, rear) diff --git "a/Target Offer/\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227.py" "b/Target Offer/7\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227.py" similarity index 62% rename from "Target Offer/\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227.py" rename to "Target Offer/7\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227.py" index 1641cc1..afd6524 100644 --- "a/Target Offer/\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227.py" +++ "b/Target Offer/7\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227.py" @@ -27,6 +27,22 @@ def jumpFloorII(self, number): ans = ans * 2 return ans +# 矩形覆盖 + # 第一次摆放一块1*2的小矩阵,则摆放方法总共为f(target-2) + # 因为,摆放了一块1*2的小矩阵(用√√表示),对应下方的1*2(用××表示)摆放方法就确定了,所以为f(targte-2) + + def rectCover(self, number): + if number == 0: + return 0 + if number == 1: + return 1 + temp = [1, 2] + + if number >= 3: + for i in range(3, number + 1): + temp[(i + 1) % 2] = temp[0] + temp[1] + return temp[(number + 1) % 2] + test = Solution() print(test.Fibonacci(100)) print(test.jumpFloor(3)) diff --git "a/Target Offer/\344\272\214\350\277\233\345\210\266\344\270\2551\347\232\204\344\270\252\346\225\260.py" "b/Target Offer/8\344\272\214\350\277\233\345\210\266\344\270\2551\347\232\204\344\270\252\346\225\260.py" similarity index 100% rename from "Target Offer/\344\272\214\350\277\233\345\210\266\344\270\2551\347\232\204\344\270\252\346\225\260.py" rename to "Target Offer/8\344\272\214\350\277\233\345\210\266\344\270\2551\347\232\204\344\270\252\346\225\260.py" diff --git "a/Target Offer/\346\225\260\345\200\274\347\232\204\346\225\264\346\225\260\346\254\241\346\226\271.py" "b/Target Offer/9\346\225\260\345\200\274\347\232\204\346\225\264\346\225\260\346\254\241\346\226\271.py" similarity index 100% rename from "Target Offer/\346\225\260\345\200\274\347\232\204\346\225\264\346\225\260\346\254\241\346\226\271.py" rename to "Target Offer/9\346\225\260\345\200\274\347\232\204\346\225\264\346\225\260\346\254\241\346\226\271.py"