最小的K个数 牛客网 剑指Offer 题目描述 输入n个整数,找出其中最小的K个数.例如输入4,5,1,6,2,7,3,8这8个数字,则最小的4个数字是1,2,3,4,. class Solution: #run:33ms memory:5732k def GetLeastNumbers_Solution(self, tinput, k): if tinput == None or len(tinput) < k or len(tinput) <= 0 or k <=0: return…
链表中倒数第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…
数字在排序数组中出现的次数 牛客网 剑指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…