数字在排序数组中出现的次数 牛客网 剑指Offer 题目描述 统计一个数字在排序数组中出现的次数. class Solution: def GetNumberOfK(self, data, k): if data == None or data == []: return 0 if len(data) == 1 and k!=data[0]: return 0 lenA = len(data) count = 0 if data[lenA/2] > k: return self.GetNumbe…
数值的整数次方 牛客网 剑指Offer 题目描述 给定一个double类型的浮点数base和int类型的整数exponent.求base的exponent次方 class Solution: #run:23ms memory:5728k def Power(self, base, exponent): flag = 0 if base == 0: return False if exponent == 0: return 1 if exponent < 0: flag = 1 ret = 1 a…
链表中倒数第K个结点 牛客网 剑指Offer 题目描述 输入一个链表,输出该链表中倒数第k个结点. # class ListNode: # def __init__(self, x): # self.val = x # self.next = None class Solution: #run:33ms memory:5728k def FindKthToTail(self, head, k): if k<=0 or head == None: return None p = head ret…