Skip to content

Instantly share code, notes, and snippets.

@tianrking
Last active September 15, 2022 06:38
Show Gist options
  • Save tianrking/af0ba92a27752c3e98cc22327976b881 to your computer and use it in GitHub Desktop.
Save tianrking/af0ba92a27752c3e98cc22327976b881 to your computer and use it in GitHub Desktop.
王天睿 实习 笔试题 行云智能

01

class ListNode:
   def __init__(self, id, name  ,father = None):
      self.id = id
      self.father = father
      self.name = name

class Solution(object):
   def deleteNode(self, node, id):
      
      while node.id is not id:
         node = node.father
      node.id = node.father.id
      node.father = node.father.father

02

class Solution:
    def GetLeastNumbers_Solution(self, tinput, k):
        n = len(tinput)
        if k <= 0 or k > n:
            return list()
        start = 0
        end = n - 1
        mid = self.partition(tinput, start, end)
        while k - 1 != mid:
            if k - 1 > mid:
                start = mid + 1
                mid = self.partition(tinput, start, end)
            elif k - 1 < mid:
                end = mid - 1
                mid = self.partition(tinput, start, end)
        res = tinput[:mid+1]
        # res.sort()
        return res
        
    def partition(self, numbers, low, high):
        key = numbers[low]
        while low < high:
            while low < high and numbers[high] >= key:
                high -= 1
            numbers[low] = numbers[high]
            while low < high and numbers[low] <= key:
                low += 1
            numbers[high] = numbers[low]
        numbers[low] = key
        return low

03

import threading

class Singleton:
    _instance = None
    lock = threading.Lock()

    def __new__(cls, *args, **kwargs):
        if cls._instance:
            return cls._instance
        else:
            with cls.lock:
                cls._instance = super().__new__(cls)
                return cls._instance

    def __init__(self, k):
        self.k = k

    def show_value(self):
        print(self.k)
    
    def show_id(cls):
        print(id(cls))
        
c = Singleton(1)
c.show_value()
c.show_id()

        
d = Singleton(2)
d.show_value()
d.show_id()

04

(^|+?86|)1(3\d|4[5-9]|5[0-9]|6[2567]|7[0-8]|8\d|9[0-35-9])\d{8}

05

0.1

Select s.sno,sname from s,sc,c where s.sno=sc.sno and c.cno=sc.cno and cname='Math'

0.2

Select s.sno,sname from s where sno not in
(Select s.sno from s,sc,c where s.sno=sc.sno and c.cno=sc.cno and cname='Math')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment