You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// You are given an integer array prices where prices[i] is the price of a given stock on the ith day.
4
+
5
+
// On each day, you may decide to buy and/or sell the stock. You can only hold at most one share of the stock at any time. However, you can buy it then immediately sell it on the same day.
6
+
7
+
// Find and return the maximum profit you can achieve.
8
+
9
+
10
+
11
+
// Example 1:
12
+
13
+
// Input: prices = [7,1,5,3,6,4]
14
+
// Output: 7
15
+
// Explanation: Buy on day 2 (price = 1) and sell on day 3 (price = 5), profit = 5-1 = 4.
16
+
// Then buy on day 4 (price = 3) and sell on day 5 (price = 6), profit = 6-3 = 3.
17
+
// Total profit is 4 + 3 = 7.
18
+
// Example 2:
19
+
20
+
// Input: prices = [1,2,3,4,5]
21
+
// Output: 4
22
+
// Explanation: Buy on day 1 (price = 1) and sell on day 5 (price = 5), profit = 5-1 = 4.
23
+
// Total profit is 4.
24
+
// Example 3:
25
+
26
+
// Input: prices = [7,6,4,3,1]
27
+
// Output: 0
28
+
// Explanation: There is no way to make a positive profit, so we never buy the stock to achieve the maximum profit of 0.
// 1319. Number of Operations to Make Network Connected
2
+
3
+
// There are n computers numbered from 0 to n - 1 connected by ethernet cables connections forming a network where connections[i] = [ai, bi] represents a connection between computers ai and bi. Any computer can reach any other computer directly or indirectly through the network.
4
+
5
+
// You are given an initial computer network connections. You can extract certain cables between two directly connected computers, and place them between any pair of disconnected computers to make them directly connected.
6
+
7
+
// Return the minimum number of times you need to do this in order to make all the computers connected. If it is not possible, return -1.
8
+
9
+
10
+
11
+
// Example 1:
12
+
13
+
14
+
// Input: n = 4, connections = [[0,1],[0,2],[1,2]]
15
+
// Output: 1
16
+
// Explanation: Remove cable between computer 1 and 2 and place between computers 1 and 3.
17
+
// Example 2:
18
+
19
+
20
+
// Input: n = 6, connections = [[0,1],[0,2],[0,3],[1,2],[1,3]]
21
+
// Output: 2
22
+
// Example 3:
23
+
24
+
// Input: n = 6, connections = [[0,1],[0,2],[0,3],[1,2]]
// There is a bi-directional graph with n vertices, where each vertex is labeled from 0 to n - 1 (inclusive). The edges in the graph are represented as a 2D integer array edges, where each edges[i] = [ui, vi] denotes a bi-directional edge between vertex ui and vertex vi. Every vertex pair is connected by at most one edge, and no vertex has an edge to itself.
4
+
5
+
// You want to determine if there is a valid path that exists from vertex source to vertex destination.
6
+
7
+
// Given edges and the integers n, source, and destination, return true if there is a valid path from source to destination, or false otherwise.
// Given an m x n 2D binary grid grid which represents a map of '1's (land) and '0's (water), return the number of islands.
4
+
5
+
// An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may assume all four edges of the grid are all surrounded by water.
0 commit comments