Snail Life

basketball dance rap


  • Home

  • Tags

  • Categories

  • Archives

  • Search

chapter2_array_matrix_algorithm

Posted on 2019-10-30 | In leetcode | | Visitors: ℃
Words count in article: 1.9k | Reading time ≈ 9

chapter2_array_matrix_algorithm

矩阵类算法

[TOC]

1. 把数组中的 0 移到末尾
1
2
3
4
5
6
7
8
9
10
11
def moveZeroes():
#遍历,数组,前面记住不为0的值,往依次迁移,遍历完数组,除记录不为0的数,直接填充为0
nums = [ 0, 1, 0, 3, 12 ]
vn = 0
for i,v in enumerate(nums):
if v != 0:
nums[vn] = v
vn += 1
nums[vn:] = [0]*(len(nums)-vn)
print(nums)
moveZeroes()
Read more »

chapter1_string_algorithm

Posted on 2019-10-30 | In leetcode | | Visitors: ℃
Words count in article: 1.5k | Reading time ≈ 7

chapter1_string_algorithm

此章节过于leetcode类,全部是关于字符串方面的算法题,包括解题思路,以及Python代码

1.1 旋转字符串

题目描述

给定一个字符串,要求把字符串前面的若干个字符移动到字符串的尾部,如把字符串“abcdef”前面的2个字符’a’和’b’移动到字符串的尾部,使得原字符串变成字符串“cdefab”。请写一个函数完成此功能,要求对长度为n的字符串操作的时间复杂度为 O(n),空间复杂度为 O(1)。

方法:三步反转法

对于这个问题,换一个角度思考一下。

Read more »

window10 快捷键

Posted on 2019-10-30 | In 巧技 | | Visitors: ℃
Words count in article: 2.3k | Reading time ≈ 8

1.常用window10 快捷键菜单

  • Win+D:显示桌面

  •   Win+E:打开资源管理器

  •   Win+I:打开设置界面

  •   Win+L:锁定屏幕

  •   Win+R:打开运行窗口

    Read more »

协程与异步I/O

Posted on 2019-10-29 | In python | | Visitors: ℃
Words count in article: 2.6k | Reading time ≈ 10

原链接

通常在Python中我们进行并发编程一般都是使用多线程或者多进程来实现的,对于CPU计算密集型任务由于GIL的存在通常使用多进程来实现,而对于IO密集型任务可以通过线程调度来让线程在执行IO任务时让出GIL,从而实现表面上的并发。

其实对于IO密集型任务我们还有一种选择就是协程。协程,又称微线程,英文名Coroutine,是运行在单线程中的“并发”,协程相比多线程的一大优势就是省去了多线程之间的切换开销,获得了更高的运行效率。Python中的异步IO模块asyncio就是基本的协程模块。

Read more »

python thread 基础概念与方法

Posted on 2019-10-29 | In python | | Visitors: ℃
Words count in article: 4.9k | Reading time ≈ 18

原链接

在Python3中,通过threading模块提供线程的功能。原来的thread模块已废弃。但是threading模块中有个Thread类(大写的T,类名),是模块中最主要的线程类,一定要分清楚了,千万不要搞混了。

threading模块提供了一些比较实用的方法或者属性,例如:

方法与属性 描述
current_thread() 返回当前线程
active_count() 返回当前活跃的线程数,1个主线程+n个子线程
get_ident() 返回当前线程
enumerater() 返回当前活动 Thread 对象列表
main_thread() 返回主 Thread 对象
settrace(func) 为所有线程设置一个 trace 函数
setprofile(func) 为所有线程设置一个 profile 函数
stack_size([size]) 返回新创建线程栈大小;或为后续创建的线程设定栈大小为 size
TIMEOUT_MAX Lock.acquire(), RLock.acquire(), Condition.wait() 允许的最大超时时间
Read more »
1…891011

snail json

您心底所憧憬的事物,一定在某个维度发生

54 posts
15 categories
21 tags
RSS
GitHub E-Mail Google 知乎

Tag Cloud

  • -- thread1
  • Anaconda1
  • Optimization1
  • algorithms27
  • db22
  • github1
  • hive2
  • linux1
  • markdown1
  • python20
  • self-study1
  • site1
  • sql2
  • statistics1
  • thread3
  • vim1
  • win10快捷键1
  • 古月山风1
  • 梦想1
  • 破晓1
  • 随笔2
© 2021 snail json | Site words total count: 137.6k
Powered by Hexo
|
Theme — NexT.Mist v5.1.4
snail silly?