程序员,音乐家(还没开始)
严肃的Blog: mentaLwz.github.io
mentalwz / gitblogofmental Goto Github PK
View Code? Open in Web Editor NEWMental's git log
Mental's git log
class Solution:
def islandPerimeter(self, grid: List[List[int]]) -> int:
length = 0
for i, e in enumerate(grid):
for j, f in enumerate(grid[i]):
curl = 0
if grid[i][j]:
if i -1 >= 0:
if grid[i-1][j]:
pass
else:
curl += 1
else:
curl += 1
if i + 1 < len(grid):
if grid[i + 1][j]:
pass
else:
curl += 1
else:
curl += 1
if j - 1 >= 0:
if grid[i][j - 1]:
pass
else:
curl += 1
else:
curl += 1
if j + 1 < len(e):
if grid[i][j + 1]:
pass
else:
curl += 1
else:
curl += 1
length += curl
return length
debug
周末和女朋友去了梅林水库,躺在草地上看着纯净的天空是相当爽,下次要带个野餐布,这次买的桌布感觉不太行。深圳的点心
真的做得不怎样,也可能是吃腻了。
其实已经搬完了,写点屁话。
原来租的自如的单间涨到3000,原来大概是2700这样子,其实差个两三百也是能接受的,但是就是不爽这种起价,一个没独卫,没电梯还在六楼的单间,tm的竟然要3000一个月。made不是出不起这个钱,而是不想这样出钱。
租了个便宜点2660的独卫公寓单间,其实就是厂房改造的公寓,怎么说,凑合住住吧。
不过现在住的地方,还真是鱼龙混杂,方圆500米内晚上各种摆脱烧烤,大排档
func sortArrayByParityII(A []int) []int {
l := len(A)
e := 0
o := 1
a := make([]int, l)
for i := 0; i< l; i++ {
if A[i] %2 == 0 {
a[e] = A[i]
e += 2
} else {
a[o] = A[i]
o += 2
}
}
return a
}
impl Solution {
pub fn sort_array_by_parity_ii(a: Vec<i32>) -> Vec<i32> {
let mut array = vec![0;a.len()];
let mut o = 1;
let mut e = 0;
for i in a {
if i % 2 == 0 {
array[e] = i;
e += 2;
} else {
array[o] = i;
o += 2;
}
}
array
}
}
class Solution:
def sortArrayByParityII(self, A: List[int]) -> List[int]:
even = []
odd = []
for i in range(len(A)):
if A[i] % 2 == 0:
even.append(A[i])
else:
odd.append(A[i])
# for i in range(len(A)):
# if i % 2 == 0:
# A[i] = even.pop()
# else:
# A[i] = odd.pop()
# ou = [i for i in A if i % 2]
# ji = [i for i in A if not i % 2]
# return [i for n in zip(ji, ou) for i in n]
return [i for n in zip(even, odd) for i in n]
test
class Solution:
def insert(self, intervals: List[List[int]], newInterval: List[int]) -> List[List[int]]:
head, tail = newInterval
placed = False
ans = list()
for li, ri in intervals:
if li > tail:
if not placed:
ans.append([head, tail])
placed = True
ans.append([li, ri])
elif ri < head:
ans.append([li, ri])
else:
head = min(head, li)
tail = max(tail, ri)
if not placed:
ans.append([head, tail])
return ans
class Solution:
def rob(self, nums: List[int]) -> int:
# 4 5 600 4 8 5 6 6 6 6
dp1 = [None for _ in nums]
dp2 = [None for _ in nums]
for i in range(len(nums)):
if i == 0:
dp1[i] = nums[i]
dp2[i] = 0
if i == 1:
dp1[i] = max(dp1[i-1], nums[i])
dp2[i] = max(dp2[i-1], nums[i])
if i >= 2:
if i < len(nums) - 1:
dp1[i] = max(dp1[i-1], nums[i] + dp1[i - 2])
dp2[i] = max(dp2[i-1], nums[i] + dp2[i - 2])
else:
dp1[i] = max(dp1[i-1], nums[i])
dp2[i] = max(dp2[i-1], nums[i] + dp2[i - 2])
return max(dp1[-1], dp2[-1])
竟然做出来了
惊闻和我同龄的表哥怀孕了,当然是他女朋友怀孕了。听到这个消息,我丝毫不感觉到喜悦,只是感觉一切都太快了。现在好像流行一种恶俗,先怀孕再结婚。在我阴暗面的想法看来,这种婚姻像是种交易,男方在县城算三分之一个富二代,家里在县城有一栋楼,村里还有一栋别墅。女方这么快就愿意未婚先孕是不是充分考虑到了对方的物质条件,我不禁这么想。
made真的感觉太快了,一切都在加速。
在这个氛围下,保持自己的节奏真tm难。
我想,谈个两三年的恋爱再结婚,不一定要小孩,不买房,买车只买特斯拉的cybertruck。
好难啊感觉。
这么多人结婚,荷包要大出血了。
不管怎样还是要经营好自己的生活。
https://tokio.rs/tokio/tutorial
rustling
读mapreduce
https://pdos.csail.mit.edu/6.824/index.html
https://github.com/chaozh/MIT-6.824
class Solution:
def moveZeroes(self, nums: List[int]) -> None:
"""
Do not return anything, modify nums in-place instead.
"""
slow, fast = 0, 0
while fast < len(nums):
if nums[fast] != 0:
nums[slow] = nums[fast]
slow += 1
fast += 1
else:
fast += 1
while slow < len(nums):
nums[slow] = 0
slow += 1
今年一定要跳槽,但是感觉自己水平还是那吊样,每天学得很少,根据自己学得很慢很少。
经历也无甚可写,但还是要逼着自己跳出去看看,不管成功还是失败
1.10点回去就 刷了个题
class Solution:
def sortByBits(self, arr: List[int]) -> List[int]:
source = dict()
arr.sort()
for i, e in enumerate(arr):
source[i] = ("{:b}".format(e), e)
sort_bin = {k: v for k, v in sorted(source.items(), key=lambda item: item[1][0].count('1'))}
# print(sort_bin)
return [v[1] for _, v in sort_bin.items()]
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def preorderTraversal(self, root: TreeNode) -> List[int]:
# ans = []
# def preorder(node):
# if not node:
# return
# ans.append(node.val)
# preorder(node.left)
# preorder(node.right)
# preorder(root)
# return ans
if not root:
return []
stacks = [root]
ans = []
while stacks:
cur = stacks.pop()
ans.append(cur.val)
if cur.right:
stacks.append(cur.right)
if cur.left:
stacks.append(cur.left)
return ans
class RandomizedCollection:
def __init__(self):
"""
Initialize your data structure here.
"""
self.d = collections.defaultdict(set)
self.v = []
def insert(self, val: int) -> bool:
"""
Inserts a value to the collection. Returns true if the collection did not already contain the specified element.
"""
self.d[val].add(len(self.v))
self.v.append(val)
return len(self.d[val]) == 1
def remove(self, val: int) -> bool:
"""
Removes a value from the collection. Returns true if the collection contained the specified element.
"""
if not self.d[val]:
return False
self.v[(i := self.d[val].pop())] = self.v[-1]
self.d[(last := self.v.pop())].discard(len(self.v))
i < len(self.v) and self.d[last].add(i)
return True
def getRandom(self) -> int:
"""
Get a random element from the collection.
"""
return random.choice(self.v)
虽然现在处境一般般,但是还是可以在这种的境遇中,提升自己的境界水平,保持内心的平静,
// When the channel is closed, the receive will immediately return.
// When we receive on a channel that is open, we cannot return until we receive the data
// signal. But if we receive on a channel that is closed, we are able to receive the signal
// without data. We know that event is occurred. Every receive on that channel will immediately
// return.
https://github.com/hoanhan101/ultimate-go/blob/master/go/concurrency/channel_1.go
发现在吃上面的开销多太多,除了让自己比较穷之外还会让自己变胖
克制
class Solution:
def uniqueOccurrences(self, arr: List[int]) -> bool:
from collections import defaultdict
count = defaultdict(int)
for e in arr:
count[e] += 1
lc = []
for c in count:
lc.append(count[c])
return len(lc) == len(set(lc))
每天都更新下。
今天和老杨,老周开了会,主持了艺术创作的会议。
工作就那样吧,晚上和同事吃了巴蜀风。
晚上刷了到简单题,os的课没认真听,要再认真看。
给老妈买了假发和餐厅服务员的头巾,因为头发掉得比较多。
搞了一把github Actions,主要参考
https://github.com/yihong0618/gitblog
以后可以在issue上写东西了,nice
有点感觉失去方向,还是要坚持学习,不要浪费时间在考虑上。
class Solution:
def wordBreak(self, s: str, wordDict: List[str]) -> List[str]:
@lru_cache(None)
def backtrack(idx):
if idx == len(s):
return [[]]
ans = list()
for i in range(idx + 1, len(s) + 1):
word = s[idx:i]
if word in wordSet:
nextWordBreaks = backtrack(i)
for nextWordBreak in nextWordBreaks:
ans.append(nextWordBreak.copy() + [word])
return ans
wordSet = set(wordDict)
breakList = backtrack(0)
return [" ".join(words[::-1]) for words in breakList]
写点自己的代码感觉还挺好,还写了makefile
class Solution:
def ladderLength(self, beginWord: str, endWord: str, wordList: List[str]) -> int:
if endWord not in wordList:
return 0
l = len(endWord)
ws = set(wordList)
head = {beginWord}
tail = {endWord}
tmp = list('abcdefghijklmnopqrstuvwxyz')
res = 1
while head:
if len(head) > len(tail):
head, tail = tail, head
q = set()
for cur in head:
for i in range(l):
for j in tmp:
word = cur[:i] + j + cur[i+1:]
if word in tail:
return res + 1
if word in ws:
q.add(word)
ws.remove(word)
head = q
res += 1
return 0
# def ladderLength(self, beginWord: str, endWord: str, wordList: List[str]) -> int:
# cases = []
# import string
# def replace(s, c , i):
# return s[:i] + c + s[i+1:]
# cases = [beginWord]
# count = 0
# exists = set()
# exists.add(beginWord)
# if endWord not in wordList:
# return 0
# wordList = set(wordList)
# while cases:
# tmp_cases = []
# count += 1
# for word in cases:
# for i, c in enumerate(list(word)):
# for sc in list(string.ascii_lowercase):
# ns = replace(word, sc, i)
# if ns == endWord:
# count += 1
# return count
# if ns in wordList:
# tmp_cases.append(ns)
# wordList.remove(ns)
# cases = tmp_cases
# # print(cases)
# return 0
教堂妹学C已经有一个来月了,但是进展感人。
说是教,其实是指导,让她看C的视频,然后去pta上做题练习,但是目前来看,还是
不太行,不太会灵活运用,融汇贯通。
所以还是需要一对一指导下。
很快她就要开学了,开学之后可能就没多少时间能够花在编程上面了。
但她开学才高一,我也是想看看高中三年能学到个什么程度,保守估计应该比我要强。
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
class Solution:
def sumNumbers(self, root: TreeNode) -> int:
ans = []
def dfs(node, cur):
if not node:
return
cur = cur + str(node.val)
if not node.left and not node.right:
# print(cur)
ans.append(cur)
dfs(node.left, cur)
dfs(node.right, cur)
dfs(root, "")
return sum([ int(x) for x in ans])
消失的情人节
幻爱
夜更
你是猪
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.