剑指offer python版 实现单例模式

class singleTon(object):
    def __init__(self,x):
        self.val=x

single2=singleTon(2)

a=single2
b=single2

print(a==b)

print(a.val)

a.val=334

print(b.val)

原文地址:https://www.cnblogs.com/xzm123/p/9847787.html

时间: 2024-11-05 22:50:38

剑指offer python版 实现单例模式的相关文章

剑指offer python版 二维数组的查找

def find_integer(matrix, num): """ :param matrix: [[]] :param num: int :return: bool """ if not matrix: return False rows, cols = len(matrix), len(matrix[0]) row, col = rows - 1, 0 while row >= 0 and col <= cols - 1: if

剑指offer python版 替换空格

print('dd dd add'.replace(' ','dd')) 原文地址:https://www.cnblogs.com/xzm123/p/9847854.html

剑指offer python版 删除链表中重复的结点

class ListNode(object): def __init__(self,x): self.val=x self.next=None class Link(object): def __init__(self,values=None): self.nodes=self.set_link(values) if values else None def get_link(self): return self.nodes def set_link(self,values): if not v

剑指offer python版 反转链表

class ListNode(object): def __init__(self,x): self.val=x self.next=None class Link(object): def __init__(self,values=None): self.nodes=self.set_link(values) if values else None def get_link(self): return self.nodes def set_link(self,values): if not v

剑指offer python版 顺时针打印矩阵

def aa(matrix): rows=len(matrix) cols=len(matrix[0]) start=0 ret=[] while start*2 <rows and start*2<cols: bb(matrix,rows,cols,start,ret) start +=1 return ret def bb(matrix,rows,cols,start,ret): row=rows-start-1 col=cols-start-1 for c in range(start,

剑指offer python版 数组中出现次数超过一半的数字

def aa(nums): if not nums: return False hashes={} ret=[] for s in nums: hashes[s]=hashes[s]+1 if hashes.get(s) else 1 if hashes[s] >len(nums)/2: ret.append(s) return list(set(ret)) print(aa([1,2,3,2,2,2,2,2,3,2,3,3,4])) 原文地址:https://www.cnblogs.com/x

剑指offer python版 礼物的最大价值

class Solution: def getmaxValue(self, values, rows, cols): if not values or rows<=0 or cols <=0: return 0 # 用于存放中间数值的临时数组 temp = [0] * cols for i in range(rows): for j in range(cols): left = 0 up = 0 if i > 0: up = temp[j] if j > 0: left = tem

剑指offer python版 数组中数值和下标相等的元素

def aa(nums): leng=len(nums) for i in range(leng): if i==nums[i]: print (i) i+=1 return None print(aa([0,1,2,3,4,5])) 原文地址:https://www.cnblogs.com/xzm123/p/9869255.html

剑指offer python版 0到n-1中缺失的数字

def aa(nums,n): for i in range(n): if i ==nums[i]: i +=1 else: return i print(aa([0,1,2,3,4,5,7],8)) 原文地址:https://www.cnblogs.com/xzm123/p/9869226.html