leetcode day7】的更多相关文章

这道题弄的心好累..  [Reverse Linked List]206 描述: Reverse a singly linked list. click to show more hints. Hint: A linked list can be reversed either iteratively or recursively. Could you implement both? 思路: 增加一个全局节点newHead,用来指向新的头部,用用一个临时节点next来遍历整个链表,用来当旧的头部…
[Q19] Given a linked list, remove the n-th node from the end of list and return its head. Example: Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from the end, the linked list becomes 1->2->3->5. Note: Giv…
还没有背单词,头晕脑胀 Num 66 加一 Plus One 注意就是进位的时候最后一位,为了省两句代码,那几个语句顺序写反覆盖的乱七八糟 vector头部插入(a.begin(),被插入的数) 如果是(a.begin()+2,被插入的数字) 是指在序号为2的前面插入(有空试一下) class Solution { public: vector<int> plusOne(vector<int>& digits) { ]; int ans; memset(a,,sizeof(…
[算法训练营day7]LeetCode454. 四数相加II LeetCode383. 赎金信 LeetCode15. 三数之和 LeetCode18. 四数之和 LeetCode454. 四数相加II 题目链接:454. 四数相加II 初次尝试 没有思路,对于map的使用还不是非常熟练,正好借这几个题多练习一下. 看完代码随想录后的想法 四个数组两两一组,写成两个嵌套的for循环,这样可以保证时间复杂度最小,其中使用map的原因是不仅要统计前两个数组的元素和,还要统计每个和出现的次数. cla…
# 增强学习成果 有一个研究成果,在学习中传授他人知识和讨论是最高效的做法,而看书则是最低效的做法(具体研究成果没找到地址).我写LeetCode博客主要目的是增强学习成果.当然,我也想出名,然而不知道能否出名. # 给算法的新手们提供一种思考方式的参考 提前说明,本人也不是高手. 算法这个东西有点玄乎.很多新手(包括我)初期入门的时候都学的是<算法导论>,然而我并不觉得<算法导论>是一本学习算法很好的书. 我们设计算法的流程,并不是像<算法导论>那样,好像天生就知道这…
终于将LeetCode的免费题刷完了,真是漫长的第一遍啊,估计很多题都忘的差不多了,这次开个题目汇总贴,并附上每道题目的解题连接,方便之后查阅吧~ 477 Total Hamming Distance 44.10% Meidum 475 Heaters  30.20% Easy 474 Ones and Zeroes  34.90% Meidum 473 Matchsticks to Square  31.80% Medium 472 Concatenated Words 29.20% Hard…
Find the length of the longest substring T of a given string (consists of lowercase letters only) such that every character in T appears no less than k times. Example 1: Input: s = "aaabb", k = 3 Output: 3 The longest substring is "aaa"…
题目链接:Path Sum II | LeetCode OJ Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum. For example: Given the below binary tree and sum = 22, 5 / \ 4 8 / / \ 11 13 4 / \ / \ 7 2 5 1 return [ [5,4,11,2],…
题目链接:Path Sum | LeetCode OJ Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum. For example: Given the below binary tree and sum = 22, 5 / \ 4 8 / / \ 11…
题目链接:Balanced Binary Tree | LeetCode OJ Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never differ by more tha…