0%

LeetCode六月挑战(6.14) Cheapest Flights Within K Stops LeetCode787解题报告

不知不觉半个月过去了,六月还有半个月哦,加油!

题目

There are n cities connected by m flights. Each flight starts from city u and arrives at v with a price w.

Now given all the cities and flights, together with starting city src and the destination dst, your task is to find the cheapest price from src to dst with up to k stops. If there is no such route, output -1.

Example 1:
Input:
n = 3, edges = [[0,1,100],[1,2,100],[0,2,500]]
src = 0, dst = 2, k = 1
Output: 200
Explanation:
The graph looks like this:
在这里插入图片描述

The cheapest price from city 0 to city 2 with at most 1 stop costs 200, as marked red in the picture.
Example 2:
Input:
n = 3, edges = [[0,1,100],[1,2,100],[0,2,500]]
src = 0, dst = 2, k = 0
Output: 500
Explanation:
The graph looks like this:
The cheapest price from city 0 to city 2 with at most 0 stop costs 500, as marked blue in the picture.
在这里插入图片描述

Read more »

LeetCode六月挑战(6.13)Largest Divisible Subset Solution解题方案

Largest Divisible Subset

Solution
Given a set of distinct positive integers, find the largest subset such that every pair (Si, Sj) of elements in this subset satisfies:

Si % Sj = 0 or Sj % Si = 0.

If there are multiple solutions, return any subset is fine.

1
2
3
4
5
6
7
8
Example 1:

Input: [1,2,3]
Output: [1,2] (of course, [1,3] will also be ok)
Example 2:

Input: [1,2,4,8]
Output: [1,2,4,8]
Read more »

Leetcode六月挑战赛(6.12)

Leetcode380 Insert Delete GetRandom O(1)

这是之前做过的一道题,我们再来详细分析一下。

题目描述

Design a data structure that supports all following operations in average O(1) time.

  1. insert(val): Inserts an item val to the set if not already present.
  2. remove(val): Removes an item val from the set if present.
  3. getRandom: Returns a random element from current set of elements. Each element must have the same probability of being returned.

Example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// Init an empty set.
RandomizedSet randomSet = new RandomizedSet();

// Inserts 1 to the set. Returns true as 1 was inserted successfully.
randomSet.insert(1);

// Returns false as 2 does not exist in the set.
randomSet.remove(2);

// Inserts 2 to the set, returns true. Set now contains [1,2].
randomSet.insert(2);

// getRandom should return either 1 or 2 randomly.
randomSet.getRandom();

// Removes 1 from the set, returns true. Set now contains [2].
randomSet.remove(1);

// 2 was already in the set, so return false.
randomSet.insert(2);

// Since 2 is the only number in the set, getRandom always return 2.
randomSet.getRandom();
Read more »

LeetCode六月挑战(6.11) Sort Color

Solution
Given an array with n objects colored red, white or blue, sort them in-place so that objects of the same color are adjacent, with the colors in the order red, white and blue.

Here, we will use the integers 0, 1, and 2 to represent the color red, white, and blue respectively.

Note: You are not suppose to use the library’s sort function for this problem.

1
2
3
4
Example:

Input: [2,0,2,1,1,0]
Output: [0,0,1,1,2,2]
Read more »

LeetCode六月挑战(6.10 ) Search Insert Position LeetCode 35

Solution
Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.

You may assume no duplicates in the array.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Example 1:

Input: [1,3,5,6], 5
Output: 2
Example 2:

Input: [1,3,5,6], 2
Output: 1
Example 3:

Input: [1,3,5,6], 7
Output: 4
Example 4:

Input: [1,3,5,6], 0
Output: 0
Read more »

NODEMCU驱动安装

工具

使用windows系统
NodeMCU驱动,有需要的朋友可以点击这里 提取码: b63t

Step1 下载驱动

下载并打开驱动包,可以看到包中含有如下文件,我的电脑是64位的,所以我们选择x64.exe驱动。

Read more »

LeetCode六月挑战 Is Subsequence LeetCode 392

Solution
Given a string s and a string t, check if s is subsequence of t.

A subsequence of a string is a new string which is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (ie, “ace” is a subsequence of “abcde” while “aec” is not).

Follow up:
If there are lots of incoming S, say S1, S2, … , Sk where k >= 1B, and you want to check one by one to see if T has its subsequence. In this scenario, how would you change your code?

Credits:
Special thanks to @pbrother for adding this problem and creating all test cases.

1
2
3
4
5
6
7
8
Example 1:

Input: s = "abc", t = "ahbgdc"
Output: true
Example 2:

Input: s = "axc", t = "ahbgdc"
Output: false

Constraints:

0 <= s.length <= 100
0 <= t.length <= 10^4
Both strings consists only of lowercase characters.

Read more »

LeetCode六月挑战(6.8)Power of Two

Power of Two

Solution

Given an integer, write a function to determine if it is a power of two.

Example 1:

1
2
3
Input: 1
Output: true
Explanation: 20 = 1

Example 2:

1
2
3
Input: 16
Output: true
Explanation: 24 = 16

Example 3:

1
2
Input: 218
Output: false
Read more »

计算机网络自顶向下方法Character1补充

本文概述:

本文主要补充计算机网络自顶向下方法第一章节的知识点。
学习书籍为:计算机网络自顶向下方法
学习视频为:国立清华大学黄能富教授讲解的计算机网络自顶向下方法,需要的可以点击 这里

Read more »