leetcode124,Leetcode: Pascal's Triangle II
Given an index?k, return the?kth?row of the Pascal's triangle. For example, given?k?= 3,Return?[1,3,3,1]. Note:Could you optimize your algorithm to use only?O(k) extra space? 分析:細節實現題。代碼如下: class Solution { public:vector&
时间:2023-11-18  |  阅读:27
哪些是I類II類工具,LeetCode Single Number I / II / III
【1】LeetCode 136 Single Number 題意:奇數個數,其中除了一個數只出現一次外,其他數都是成對出現,比如1,2,2,3,3...,求出該單個數。 解法:容易想到異或的性質,兩個相同的數異或為0,那么把這串數從頭到尾異或起來&#
时间:2023-11-18  |  阅读:26
leetcode股票最大收益,leetcode最大矩形_柱狀圖中的最大矩形
難度:困難給定 n 個非負整數,用來表示柱狀圖中各個柱子的高度。每個柱子彼此相鄰,且寬度為 1 。leetcode股票最大收益、求在該柱狀圖中,能夠勾勒出來的矩形的最大面積。以上是柱狀圖的示例,其中每個柱子的寬度為 1,給定的高度為 [2
时间:2023-11-12  |  阅读:23
LEETCODE,leetcode—sqrt
1.題目描述 ? Implement int sqrt(int x). ? Compute and return the square root of x. LEETCODE。2.解法分析 很明顯,用二分搜索可解,但是需要防止溢出,所以中間結果和上界下界都要用long long 來保存。 class Solution { public: int sqrt(int x) { /
时间:2023-11-09  |  阅读:22
leetCode,LeetCode Number of Digit One
原題鏈接在這里:https://leetcode.com/problems/number-of-digit-one/ 每10個數, 有一個個位是1, 每100個數, 有10個十位是1, 每1000個數, 有100個百位是1.? 做一個循環, 每次計算單個位上1得總個數(個位,十位, 百位).?? 例子: 以算百位上1為例子: ? 假設百位上是0, 1,
时间:2023-11-07  |  阅读:23
leetCode,LeetCode  Binary Tree Right Side View (DFS/BFS)
? ? leetCode?題意:   給一棵二叉樹,要求收集每層的最后一個節點的值。按從頂到底裝進vector返回。 ? 思路:   BFS比較簡單,先遍歷右孩子就行了。 1 /** 2 * Definition for a binary tree node. 3 * struct TreeNode { 4 * int val; 5 * Tr
时间:2023-11-07  |  阅读:24
leetcode15,Leetcode 169 Majority Element
Given an array of size?n, find the majority element. The majority element is the element that appears?more than?? n/2 ??times. You may assume that the array is non-empty and the majority element always exist in the array. 題目大意: 給定一個長度為n的
时间:2023-11-07  |  阅读:24
LEETCODE,leetcode-Basic Calculator-224
輸入一個字符串,包含數字或者+,-,(,),求這個表達式的結果 1.沒有括號時順序執行 2.有括號時先計算括號內的表達式 這里用一個棧來保存遇到括號(之前的表達式的結果,也就是說沒遇到括號之前,按順序正常執行設結果為x,遇到括號之后要先
时间:2023-11-07  |  阅读:25
leetCode,LeetCode62 Unique Paths
題目: leetCode,A robot is located at the top-left corner of a?m?x?n?grid (marked 'Start' in the diagram below). The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the
时间:2023-11-07  |  阅读:22
leetcode15,LeetCode91 Decode Ways
題目: A message containing letters from?A-Z?is being encoded to numbers using the following mapping: 'A' -> 1 'B' -> 2 ... 'Z' -> 26 Given an encoded message containing digits, determine the total number of ways to
时间:2023-11-07  |  阅读:21

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息