莉莉丝9.6笔试讨论
a了2.3
第一题百分之80,复杂度已经的O(n)了,要O(logn)能想到就是递归,想了半天,太麻烦了放弃了
class Solution: def formatList(self , head ): if not head: return head index=head head=head.next i=index flag=0 while head: if flag==0: i.next=head i=i.next head=head.next flag=1 else: a=head head=head.next a.next=index index=a flag=0 return index第二题Ac
class Solution:
def sortList(self , head ):
dic={}
while head:
if head.val in dic:
dic[head.val]+=1
else:
dic[head.val]=1
head=head.next
a=sorted(dic.items())
k=[]
for ass in a:
k.append([ass[0],ass[1]])
res=ListNode(0)
now=res
num=max(dic.values())
for i in range(num):
for item in k:
if item[1]>0:
now.next=ListNode(item[0])
now=now.next
item[1]=item[1]-1
return res.next 第三题百分之50%,这种题都能超时,算了,累了,休息 num = int(input()) data = [] for i in range(num): a = input().split() if 'in' == a[0]: data.append([int(a[1]), a[2]]) else: if not data: print(-1) continue else: a[1]=int(a[1]) if a[1]==0: print(data.pop(0)[1]) continue else: flag=0 for item in data: if a[1]==int(item[0]): print(item[1]) data.remove(item) flag=1 break if flag==0: print(-1)