avatar
Siz Long

My name is Siz. I am a computer science graduate student specializing in backend development with Golang and Python, seeking opportunities in innovative tech projects. My personal website is me.longsizhuo.com .Connect with me on LinkedIn: https://www.linkedin.com/in/longsizhuo/.

  • Resume
  • Archives
  • Categories
  • Photos
  • Music



{{ date }}

{{ time }}

avatar
Siz Long

My name is Siz. I am a computer science graduate student specializing in backend development with Golang and Python, seeking opportunities in innovative tech projects. My personal website is me.longsizhuo.com .Connect with me on LinkedIn: https://www.linkedin.com/in/longsizhuo/.

  • 主页
  • Resume
  • Archives
  • Categories
  • Photos
  • Music

One question daily 2283

  2024-01-01
字数统计: 106字   |   阅读时长: 1min

2283.Determine whether the number of a number is equal to the value of the digital position。

1
2
3
4
5
6
7
8
9
10
class Solution:
def digitCount(self, num: str) -> bool:
hash_1 = {}
for index, i in enumerate(num):
if int(i) != 0:
hash_1[str(index)] = int(i)
hash_2 = Counter(num)
if hash_1 == dict(hash_2):
return True
return False

I read this question for a while,MeaningindexRead,indexAppearnum[index]Second-rate,1210that is”0Appear1Second-rate,”1Appear2Second-rate,”2Appear1Second-rate,”3Appear0Second-rate。ThennumJust count the things in。

Because I was doing the practice of hash table two days ago,So at a glance at this question,Use directlyCounterFunction counts,Compare,Finish

  • Python
  • solved,answer

show all >>

One question daily 2293. Great mini game

  2024-01-01
字数统计: 331字   |   阅读时长: 2min

Although it is a simple question,But there are recursive ideas。

Constantly convert the one -dimensional list into a two -dimensional list for operation(This can be avoidedindexChaos caused by changes)

Then useflagCount,Comparison of maximum and minimum values。

Just return to the end,Although it must be returned to a number,Still‘nums[0]’To avoid warning。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
2293. Great mini game
Simple
39
company
Google Google
Give you a bidding 0 Started integer array nums ,Its length is 2 Power。

right nums Execute the following algorithm:

set up n equal nums length,if n == 1 ,termination Algorithm。otherwise,create A new integer array newNums ,The length of the new array is n / 2 ,Bidding from 0 start。
right于满足 0 <= i < n / 2 Every even Bidding i ,Will newNums[i] Assignment for min(nums[2 * i], nums[2 * i + 1]) 。
right于满足 0 <= i < n / 2 Every odd number Bidding i ,Will newNums[i] Assignment for max(nums[2 * i], nums[2 * i + 1]) 。
use newNums replace nums 。
From steps 1 start repeat the whole process。
After executing the algorithm,return nums The remaining numbers。



Exemplary example 1:



enter:nums = [1,3,5,2,4,8,2,2]
Output:1
explain:repeat执行算法会得到下述数组。
first round:nums = [1,5,4,2]
second round:nums = [1,4]
Third round:nums = [1]
1 Is the last number left,return 1 。
Exemplary example 2:

enter:nums = [3]
Output:3
explain:3 Is the last number left,return 3 。


hint:

1 <= nums.length <= 1024
1 <= nums[i] <= 109
nums.length yes 2 Power

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class Solution:
def minMaxGame(self, nums: List[int]) -> int:
flag = 0
while len(nums) > 1:
nums = [nums[i:i + 2] for i in range(0, len(nums), 2)]
# Divide2dimension
for i in range(len(nums)):
if flag % 2 == 0:
nums[i] = min(nums[i])
flag += 1
else:
nums[i] = max(nums[i])
flag += 1
return nums[0]

  • Python
  • solved,answer

show all >>

One question daily 2299. Code inspection device II

  2024-01-01
字数统计: 283字   |   阅读时长: 1min

2023-01-20.png

Excess when executing100%User,What can I say about this question,But oneBit operationKnowledge point

My code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
class Solution:
def strongPasswordCheckerII(self, password: str) -> bool:
flag1 = flag2 = flag3 = flag4 = 1
ret = None
for i in password:
if ret == i:
return False
if i.isdigit():
flag1 = 0
elif i.isupper():
flag2 = 0
elif i.islower():
flag3 = 0
else:
flag4 = 0
ret = i
if sum([flag1, flag2, flag3, flag4]) == 0 and len(password) >= 8:
return True
return False

Bit operation代码:

method one:simulation + Bit operation

According to the description of the topic,我们可以simulation检查密码是否满足题目要求的过程。

first,We check whether the length of the password is less than 8,in the case of,Then return false。

Next,We use a mask mask To record whether the password contains a lowercase letter、uppercase letter、Numbers and special characters。We traverse the password,Like a character every time,First determine whether it is the same as the previous character,in the case of,Then return false。Then,Update mask according to the type of character mask。at last,We check the mask mask Whether it is 15,in the case of,Then return true,否Then return false。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
class Solution:
def strongPasswordCheckerII(self, password: str) -> bool:
if len(password) < 8:
return False
mask = 0
for i, c in enumerate(password):
if i and c == password[i - 1]:
return False
if c.islower():
mask |= 1
elif c.isupper():
mask |= 2
elif c.isdigit():
mask |= 4
else:
mask |= 8
return mask == 15

author:ylb
Link:https://leetcode.cn/problems/strong-password-checker-ii/solutions/2068878/by-lcbin-hk2a/

  • Python
  • answer
  • Bit operation

show all >>

2303. Calculate the total taxable amount

  2024-01-01
字数统计: 270字   |   阅读时长: 1min

2023-01-23 (2).png
2303. Calculate the total taxable amount

Thought:

Sit a long time,It feels rare“Simple”。Not to do,The solution of the question。There are many judgments,So I wrote a lot of judgments,The more you write, the more you feel wrong。

Let’s take a look at the official solution

Code:

错误Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from typing import List

class Solution:
def calculateTax(self, brackets: List[List[int]], income: int) -> float:
if income == 0:
return 0
tax: float = 0
index: int = 1
if income < brackets[0][0]:
return income * brackets[0][1] / 100
else:
tax += brackets[0][0] * brackets[0][1] / 100
while index < len(brackets):
# Judging whether it is the last one
if index == len(brackets) - 1:
# ComparebracketsThe last one is still big
if income - brackets[index][0] < 0:
tax += (income - brackets[index - 1][0]) * brackets[index][1] / 100
return tax
if income >= brackets[index][0]:
tax += (brackets[index][0]- brackets[index-1][0]) * brackets[index][1] / 100
if income < brackets[index-1][0]:
break
index += 1
return tax

print(Solution.calculateTax(Solution(), brackets = [[1,0],[4,25],[5,50]], income = 2))

Let’s take a look at the official solution

1
2
3
4
5
6
7
8
9
10
class Solution:
def calculateTax(self, brackets: List[List[int]], income: int) -> float:
totalTax = lower = 0
for upper, percent in brackets:
tax = (min(income, upper) - lower) * percent
totalTax += tax
if income <= upper:
break
lower = upper
return totalTax / 100

@ylb

1
2
3
4
5
6
7
class Solution:
def calculateTax(self, brackets: List[List[int]], income: int) -> float:
ans = prev = 0
for upper, percent in brackets:
ans += max(0, min(income, upper) - prev) * percent
prev = upper
return ans / 100
  • Python
  • math
  • unsolved

show all >>

2309. The best English letters with both appropriates and lowercases One question daily

  2024-01-01
字数统计: 424字   |   阅读时长: 2min

2023-01-27 (3).png
2309. The best English letters with both appropriates and lowercases

Thought:

  1. Hash table:The first thing to think of the question is to solve it with a dictionary。But find that you can directly traverse the alphabet,fromZStart looking for,See if the applause exists,Just return directly。
    9f9081c1d70b0d0e0f736c400e4ddb3.png
    Running time exceeds99.9%
  2. Bit operation:We can use two integers mask1 and mask2 Record string separately s 中出现的小写字母and大写字母,in mask1 First i
    Position representation i Does a lowercase letter appear,and mask2 First i Position representation i Whether an uppercase letter appears。

Then we will mask1 and mask2 Perform and calculate,The results obtained mask First i Position representation i Whether the lethals of the letter appear at the same time。

As long as you get mask The highest level of binary representation 1 s position,Convert it to the corresponding capital letter。If all binary positions are not 1,Explain that there is no letter that appears at the same time,,Return to an empty string。

author:ylb
Link:https://leetcode.cn/problems/greatest-english-letter-in-upper-and-lower-case/solutions/2077636/by-lcbin-zbg0/
source:Deduction(LeetCode)
著作权归author所有。商业转载请联系author获得授权,Non -commercial reprint Please indicate the source。

Code:

Traversing the alphabet
1
2
3
4
5
6
class Solution:
def greatestLetter(self, s: str) -> str:
for i in range(90, 64, -1):
if chr(i) in s and chr(i+32) in s:
return chr(i)
return ""
Hash table
1
2
3
4
5
6
7
8
9
10
11
12
class Solution {
public:
string greatestLetter(string s) {
unordered_set<char> strin(s.begin(),s.end());
for(char c = 'Z'; c >= 'A'; --c){
if(strin.count(c) && strin.count(char(c+32))){
return string(1,c);
}
}
return "";
}
};
Bit operation
1
2
3
4
5
6
7
8
9
10
11
12
13
class Solution:
def greatestLetter(self, s: str) -> str:
# We can use two integers mask1 and mask2
# Record string separately s 中出现的小写字母and大写字母,in mask1 First i Position representation i Does a lowercase letter appear,
# and mask2 First i Position representation i Whether an uppercase letter appears。
mask1 = mask2 = 0
for i in s:
if i.islower():
mask1 |= 1 << (ord(i) - ord("a"))
else:
mask2 |= 1 << (ord(i) - ord("A"))
mask = mask1 & mask2
return chr(mask.bit_length() - 1 + ord("A")) if mask else ""
  • Python
  • answer
  • Hash table
  • One question daily
  • C++
  • Bit operation

show all >>

2315. Statistical star number One question daily

  2024-01-01
字数统计: 119字   |   阅读时长: 1min

2023-01-29.png
2315. Statistical star number

Thought:

mine:The simple version of the simple out of the stack into the stack
@ylq:right|Number count,The number is2Perform the multiple*Count

Code:

Out of the stack into the stack
1
2
3
4
5
6
7
8
9
10
11
12
13
class Solution:
def countAsterisks(self, s: str) -> int:
stack = True
flag = 0
for i in s:
if stack:
if i == '*':
flag += 1
if i == '|' and stack:
stack = False
elif i == '|' and not stack:
stack = True
return flag
ylq
1
2
3
4
5
6
7
8
9
class Solution:
def countAsterisks(self, s: str) -> int:
count1, count2 = 0, 0
for i in range(len(s)):
if s[i] == '|':
count1 += 1
if count1 % 2 == 0 and s[i] == '*':
count2 += 1
return count2
  • Python
  • answer
  • One question daily

show all >>

2325Decrypt One question daily

  2024-01-01
字数统计: 160字   |   阅读时长: 1min

2023-02-01 (1).png
2325. Decrypt

Thought:

Simple hash mapping table,pythonUse ascii_lowercase[] Directly obtain a lowercase letter。
Golang Look at the answer of Lingshen,

“Imam on the space to the space,In this way, you don’t need to judge the space。”

Code:

python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
from string import ascii_lowercase

class Solution:
def decodeMessage(self, key: str, message: str) -> str:
str1 = ''
dict1 = {}
index = 0
for i in key.replace(' ', ''):
if i not in dict1:
dict1[i] = ascii_lowercase[index]
index += 1
for i in message:
if i in dict1:
str1 += dict1[i]
else:
str1 += ' '
return str1
golang
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
func decodeMessage(key string, message string) string {
mp := ['z' + 1]byte{' ': ' '}
cur := byte('a')
for _, c := range key {
if mp[c] == 0 {
mp[c] = cur
cur += 1
}
}
s := []byte(message)
for i, c := range s {
s[i] = mp[c]
}
return string(s)
}

  • Python
  • answer
  • Hash table
  • One question daily
  • golang

show all >>

2331Calculate the value of the Boolean binary tree One question daily

  2024-01-01
字数统计: 170字   |   阅读时长: 1min

topic:

2023-02-06.png
2331Calculate the value of the Boolean binary tree

Thought:

For the currentroot,in the case ofleaf root(That is, the left node is empty),Then judge the current Boolean value(The leaf node must be Boolean instead of judging)。
Otherwise,Until traversing the leaf node,After seeing the left and right children of a sub -tree,Judge the current Valtype,Finally seekingValValue。
ifValNot the root node,butValChildren’s nodes as other trees return to the previous layer。

Code:

1
2
3
4
5
6
7
class Solution:
def evaluateTree(self, root: Optional[TreeNode]) -> bool:
if root.left is None:
return bool(root.val)
l = self.evaluateTree(root.left)
r = self.evaluateTree(root.right)
return l or r if root.val == 2 else l and r
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
type TreeNode struct {
Val int
Left *TreeNode
Right *TreeNode
}

func evaluateTree(root *TreeNode) bool {
if root.Left == nil {
return root.Val == 1
}
l, r := evaluateTree(root.Left), evaluateTree(root.Right)
if root.Val == 2 {
return l || r
}
return l && r
}
  • Python
  • answer
  • Binary tree

show all >>

2319Determine whether the matrix is ​​one X matrix One question daily

  2024-01-01
字数统计: 141字   |   阅读时长: 1min

topic:

2023-01-31 (2).png
2319. Determine whether the matrix is ​​one X matrix

Thought:

GolangPure violence,PythonLearn Spirit God
The downward bidding on the main diagonal needs to be satisfied:i=j
Opposition to the corner line is satisfied:i+j=n−1

Code:

1
2
3
4
5
class Solution:
def checkXMatrix(self, grid: List[List[int]]) -> bool:
return all(
(v != 0) == (i == j or i + j == len(grid) - 1) for i, row in enumerate(grid) for j, v in enumerate(row))

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
func checkXMatrix(grid [][]int) bool {
for i := 0; i < len(grid); i++ {
for j := 0; j < len(grid[i]); j++ {
//Two numbers in the first line
if (i == j) || (i+j == len(grid)-1) {
if grid[i][j] == 0 {
return false
}
} else if grid[i][j] != 0 {
return false
}
}
}
return true
}
  • Python
  • answer

show all >>

2335. The shortest total time to be filled with a cup One question daily

  2024-01-01
字数统计: 291字   |   阅读时长: 1min

topic:

2023-02-11.png
2335. The shortest total time to be filled with a cup.md

Thought:

  1. This question is very simple,但是我好像没用贪心的Thought。Look at the second test case and find it found,In fact, the minimum number of seconds is to avoid a certain number as much as possible0。
    So keep sorting,Always operate the two largest numbers。This sending can also be used for DoriamountCase,But because of sorting,I don’t know if it can be used for a large number。
    Look atylbBig,和我一样但是Big细节处理得很好,Two fewer judgments than me,Then it seems that the classification discussion method below may be a solution to the difficult situation。
  2. mathematical method?Sort the number of drinks from small to large,Set the quantity x,y,z。Our goal is to match the different drinks as much as possible。
    like$x+y<=z$,The answer isz。like反之,Then set$t=(x+y-z)$,t是偶数The answer is
    $ \frac{t−1}{2} +z$Plus one

Code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
class Solution:
def fillCups(self, amount: List[int]) -> int:
amount.sort()
count = 0
# Try to avoid returning0
while amount[-1] > 0:
if amount[-1] > 0 and amount[1] > 0:
amount[-1] -= 1
amount[1] -= 1
count += 1
if amount[-1] > 0 and amount[1] == 0:
return count + amount[-1]
amount.sort()
return count
ylb-golang
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import "sort"

func fillCups(amount []int) int {
ans := 0
for amount[0] + amount[1] + amount[2] > 0 {
sort.Ints(amount)
ans ++
amount[2] --
if amount[1] > 0{
amount[1] --
}
}
return ans
}
  • Python
  • answer
  • One question daily
  • golang
  • dp

show all >>

<< 上一页1…678910…16下一页 >>

153 篇 | 133k
次 | 人
这里自动载入天数这里自动载入时分秒
2022-2025 loong loong | 新南威尔士龙龙号