Coder Social home page Coder Social logo

gitblogofmental's Introduction

Gitblog

My personal blog using issues and GitHub Actions (随意转载,无需署名) RSS Feed

友情链接

Name Link Desc

最近更新

Leetcode2020

显示更多

2023

2020

显示更多

2020 学了个Diao

2020Movie

2021

Golang

Tutorial

教育

术语

记录

TODO

TODO list from TODO all done

gitblogofmental's People

Contributors

mentalwz avatar

Stargazers

cgrrty avatar  avatar

Watchers

 avatar

gitblogofmental's Issues

TODO

抄cheat sheet golang rust

full stack

3语言刷题

Movie to Look

Movie to Look

想看的

  • 消失的情人节

  • 幻爱

  • 夜更

  • 你是猪

想看不敢看

  • 无声

值得一看

  • 孤味

463. 岛屿的周长

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

127. 单词接龙

双端bfs

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


Go tips

  • new(T) - Allocates memory, and sets it to the zero value for type T..
    new分配内存, 对于整数是0,字符串是空字符串,对于slice,map,channel(referenced type 引用类型)则是nil
    由于引用类型的底层数据结构也是指针,所以 new([]int)这种操作不会给切片分配内存空间(返回的是slice的指针)
  • make(T) 则对于引用类型分配内存后,并对其底层数据结构初始化(length capacity)。如,make([]int, 5)返回的非指针而是slice

及时反馈加持之以恒

教堂妹学C已经有一个来月了,但是进展感人。
说是教,其实是指导,让她看C的视频,然后去pta上做题练习,但是目前来看,还是
不太行,不太会灵活运用,融汇贯通。
所以还是需要一对一指导下。
很快她就要开学了,开学之后可能就没多少时间能够花在编程上面了。
但她开学才高一,我也是想看看高中三年能学到个什么程度,保守估计应该比我要强。

140. 单词拆分 II

了解到@lru_cache(None)

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] 

一切都太快

惊闻和我同龄的表哥怀孕了,当然是他女朋友怀孕了。听到这个消息,我丝毫不感觉到喜悦,只是感觉一切都太快了。现在好像流行一种恶俗,先怀孕再结婚。在我阴暗面的想法看来,这种婚姻像是种交易,男方在县城算三分之一个富二代,家里在县城有一栋楼,村里还有一栋别墅。女方这么快就愿意未婚先孕是不是充分考虑到了对方的物质条件,我不禁这么想。

made真的感觉太快了,一切都在加速。
在这个氛围下,保持自己的节奏真tm难。
我想,谈个两三年的恋爱再结婚,不一定要小孩,不买房,买车只买特斯拉的cybertruck。
好难啊感觉。

这么多人结婚,荷包要大出血了。

不管怎样还是要经营好自己的生活。

记录

写点自己的代码感觉还挺好,还写了makefile

又开始更新

每天都更新下。
今天和老杨,老周开了会,主持了艺术创作的会议。
工作就那样吧,晚上和同事吃了巴蜀风。
晚上刷了到简单题,os的课没认真听,要再认真看。
给老妈买了假发和餐厅服务员的头巾,因为头发掉得比较多。

Road map

Backend

Internet

  1. DNS and how it works
  2. What is Domain Name
  3. What is hosting
  4. How does the internet work
  5. What is HTTP

OS and General Knowledge

  1. Terminal Usage
  2. How OSs work in general
  3. Process Management
  4. Thread and Concurrency
  5. Memory Management
  6. Interprocess Communication
  7. I/O management
  8. POSIX Basics stdin, stdout, stderr, pipes
  9. Basic Networking Concepts

1207. 独一无二的出现次数

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))

381. O(1) 时间插入、删除和获取随机元素 - 允许重复

:= 的语法,还要and 可以这么用

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)

被过度消耗的生命

虽然现在处境一般般,但是还是可以在这种的境遇中,提升自己的境界水平,保持内心的平静,

1356. 根据数字二进制下 1 的数目排序

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()]

开支要节省

发现在吃上面的开销多太多,除了让自己比较穷之外还会让自己变胖
克制

记搬家

其实已经搬完了,写点屁话。
原来租的自如的单间涨到3000,原来大概是2700这样子,其实差个两三百也是能接受的,但是就是不爽这种起价,一个没独卫,没电梯还在六楼的单间,tm的竟然要3000一个月。made不是出不起这个钱,而是不想这样出钱。
租了个便宜点2660的独卫公寓单间,其实就是厂房改造的公寓,怎么说,凑合住住吧。

不过现在住的地方,还真是鱼龙混杂,方圆500米内晚上各种摆脱烧烤,大排档

129. 求根到叶子节点数字之和

# 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])

一月的碎碎念

记录

周末和女朋友去了梅林水库,躺在草地上看着纯净的天空是相当爽,下次要带个野餐布,这次买的桌布感觉不太行。深圳的点心
真的做得不怎样,也可能是吃腻了。

想法

  • 看完操作系统和网络的书
  • 设计模式认证看看
  • 剑指刷熟练
  • 看go相关视频和源码

重要

  • 2021要坚持记录,而且要留下痕迹
  • 内心上还是要让自己更强大一点,其实也就是更勇敢一点
  • 增加生活的秩序,减少熵
  • 少刷手机进行无意义的挥霍光阴
  • 坐在沙发上用笔记本,不要在床上用电脑,不然颈椎容易报废
  • 继续思考,实践

922. 按奇偶排序数组 II

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]

lc.213

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])

竟然做出来了

283. 移动零

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

茫茫然

有点感觉失去方向,还是要坚持学习,不要浪费时间在考虑上。

144 二叉树的前序遍历

144 二叉树的前序遍历

# 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 

57. 插入区间

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

硬着头皮学习

今年一定要跳槽,但是感觉自己水平还是那吊样,每天学得很少,根据自己学得很慢很少。
经历也无甚可写,但还是要逼着自己跳出去看看,不管成功还是失败

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.