Loading

合集-手撕算法

摘要:数组,字符串 最后一个单词长度 class Solution: def lengthOfLastWord(self, s: str) -> int: end = len(s) - 1 while s[end] == " ": end -= 1 start = end while start >= 0 阅读全文
posted @ 2024-07-04 10:47 Duancf 阅读(6) 评论(0) 推荐(0) 编辑
摘要:有效的电话号码 grep -E '^(\([0-9]{3}\) [0-9]{3}-[0-9]{4}|[0-9]{3}-[0-9]{3}-[0-9]{4})$' file.txt 打印第十行 awk "NR==10" file.txt sed -n '10p' file.txt tail -n +10 阅读全文
posted @ 2024-09-05 10:38 Duancf 阅读(5) 评论(0) 推荐(0) 编辑
摘要:删除重复的电子邮箱 delete from Person where id not in (select id from (select min(id) as id from Person group by email) as temp) 好友申请 II :谁有最多的好友 select id,cou 阅读全文
posted @ 2024-09-11 10:14 Duancf 阅读(5) 评论(0) 推荐(0) 编辑
摘要:懒汉式 public class Singleton { private static Singleton instance; private Singleton (){} public static Singleton getInstance() { if (instance == null) { 阅读全文
posted @ 2024-07-09 19:18 Duancf 阅读(6) 评论(0) 推荐(0) 编辑
摘要:多线程循环打印ABC import java.util.concurrent.locks.Condition; import java.util.concurrent.locks.ReentrantLock; public class Main { public static ReentrantLo 阅读全文
posted @ 2024-09-01 14:14 Duancf 阅读(19) 评论(0) 推荐(0) 编辑
摘要:两个线程交替打印0-100 import java.util.concurrent.locks.Condition; import java.util.concurrent.locks.ReentrantLock; public class Main { public static Reentran 阅读全文
posted @ 2024-09-01 14:15 Duancf 阅读(42) 评论(0) 推荐(0) 编辑
摘要:首先来看线程不安全的转账 public class Bank { private int[] accounts; public Bank() { this.accounts = new int[10]; for (int i = 0; i < 10; i++) { accounts[i] = 100 阅读全文
posted @ 2024-08-22 20:37 Duancf 阅读(25) 评论(0) 推荐(0) 编辑
摘要:一种不安全的写法 public class Main { public static final Object lock1 = new Object(); public static final Object lock2 = new Object(); public static void main 阅读全文
posted @ 2024-09-19 14:26 Duancf 阅读(7) 评论(0) 推荐(0) 编辑
摘要:import java.util.LinkedList; import java.util.Queue; import java.util.concurrent.locks.Condition; import java.util.concurrent.locks.ReentrantLock; pub 阅读全文
posted @ 2024-09-27 21:45 Duancf 阅读(24) 评论(0) 推荐(0) 编辑
摘要:public class Main { public static void main(String[] args) throws InterruptedException, FileNotFoundException { try(FileInputStream file = new FileInp 阅读全文
posted @ 2024-09-28 22:18 Duancf 阅读(28) 评论(0) 推荐(0) 编辑
摘要:import java.io.*; import java.sql.Time; import java.util.*; import java.util.concurrent.*; import java.util.concurrent.atomic.AtomicInteger; import ja 阅读全文
posted @ 2024-09-30 16:53 Duancf 阅读(5) 评论(0) 推荐(0) 编辑
摘要:# Definition for singly-linked list. # class ListNode: # def __init__(self, val=0, next=None): # self.val = val # self.next = next class Solution: def 阅读全文
posted @ 2024-09-09 09:04 Duancf 阅读(3) 评论(0) 推荐(0) 编辑
摘要:# Definition for singly-linked list. # class ListNode: # def __init__(self, val=0, next=None): # self.val = val # self.next = next class Solution: def 阅读全文
posted @ 2024-09-17 15:39 Duancf 阅读(6) 评论(0) 推荐(0) 编辑
摘要:# Definition for singly-linked list. # class ListNode: # def __init__(self, val=0, next=None): # self.val = val # self.next = next class Solution: def 阅读全文
posted @ 2024-09-10 11:44 Duancf 阅读(5) 评论(0) 推荐(0) 编辑
摘要:# Definition for singly-linked list. # class ListNode: # def __init__(self, val=0, next=None): # self.val = val # self.next = next class Solution: def 阅读全文
posted @ 2024-09-27 10:03 Duancf 阅读(10) 评论(0) 推荐(0) 编辑
摘要:# Definition for singly-linked list. # class ListNode: # def __init__(self, x): # self.val = x # self.next = None class Solution: def removeDuplicateN 阅读全文
posted @ 2024-09-28 11:28 Duancf 阅读(7) 评论(0) 推荐(0) 编辑
摘要:检测环 快慢指针法是一种用于检测链表中是否存在环的有效方法,同时也可以找到环的起点。该方法的原理基于两个指针在链表上同时移动,其中一个移动得更快,而另一个移动得更慢。 检测环的存在: 使用两个指针,一个称为快指针(fast),一个称为慢指针(slow)。 在每一步中,快指针向前移动两步,而慢指针只移 阅读全文
posted @ 2024-08-31 11:32 Duancf 阅读(32) 评论(0) 推荐(0) 编辑
摘要:# Definition for singly-linked list. # class ListNode: # def __init__(self, val=0, next=None): # self.val = val # self.next = next class Solution: def 阅读全文
posted @ 2024-09-23 10:21 Duancf 阅读(3) 评论(0) 推荐(0) 编辑
摘要:class Node: def __init__(self, key=0, val=0, pre=None, next=None, fre=0, tail=None): self.key = key self.val = val self.pre = pre self.next = next sel 阅读全文
posted @ 2024-09-01 14:09 Duancf 阅读(12) 评论(0) 推荐(0) 编辑
摘要:class Node: def __init__(self, key=0, value=0): self.key = key self.value = value self.prev = None self.next = None class LRUCache: def __init__(self, 阅读全文
posted @ 2024-09-01 14:13 Duancf 阅读(10) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示