leetcode学习总结】的更多相关文章

源代码地址:https://github.com/hopebo/hopelee 语言:C++ 517. Super Washing Machines You have n super washing machines on a line. Initially, each washing machine has some dresses or is empty. For each move, you could choose any m (1 ≤ m ≤ n) washing machines,…
源代码地址:https://github.com/hopebo/hopelee 语言:C++ 24.Swap Nodes in Pairs Given a linked list, swap every two adjacent nodes and return its head. For example,Given 1->2->3->4, you should return the list as 2->1->4->3. Your algorithm should u…
题目1 ID121 给定一个数组,它的第 i 个元素是一支给定股票第 i 天的价格. 如果你最多只允许完成一笔交易(即买入和卖出一支股票),设计一个算法来计算你所能获取的最大利润. 注意你不能在买入股票前卖出股票. 示例 1: 输入: [7,1,5,3,6,4]输出: 5解释: 在第 2 天(股票价格 = 1)的时候买入,在第 5 天(股票价格 = 6)的时候卖出,最大利润 = 6-1 = 5 . 注意利润不能是 7-1 = 6, 因为卖出价格需要大于买入价格. 示例 2: 输入: [7,6,4…
题目1 ID面试题 01.04 给定一个字符串,编写一个函数判定其是否为某个回文串的排列之一. 回文串是指正反两个方向都一样的单词或短语.排列是指字母的重新排列. 回文串不一定是字典当中的单词. 示例1: 输入:"tactcoa" 输出:true(排列有"tacocat"."atcocta",等等) 我的解答: bool canPermutePalindrome(char* s){     int num[200]={0};     int i,…
Author       : Email         : vip_13031075266@163.com Date          : 2021.03.07 Version     : 北京 Copyright : 未经同意不得转载!!! Reference:https://leetcode-cn.com/problemset/all/ 写给自己的序: 从事LinuxC开发有3年了,这期间基本都是使用C语言写bug.日常工作除了薪资赶不上其他语言,其余各方面感觉C语言还是挺棒的.我偶尔刷l…
1 LeetCode是什么? LeetCode是一个在线的编程测试平台,国内也有类似的Online Judge平台.程序开发人员可以通过在线刷题,提高对于算法和数据结构的理解能力,夯实自己的编程基础.对于找工作的小伙伴十分有好处. 这是leetcode官网的简介: LeetCode OJ is a platform for preparing technical coding interviews. Pick from an expanding library of more than 190 …
645. Set Mismatch The set S originally contains numbers from 1 to n. But unfortunately, due to the data error, one of the numbers in the set got duplicated to another number in the set, which results in repetition of one number and loss of another nu…
源代码地址:https://github.com/hopebo/hopelee 语言:C++ 301. Remove Invalid Parentheses Remove the minimum number of invalid parentheses in order to make the input string valid. Return all possible results. Note: The input string may contain letters other tha…
之前断了一段时间没做Leetcode,深感愧疚,重新续上 题目1 ID104 给定一个二叉树,找出其最大深度. 二叉树的深度为根节点到最远叶子节点的最长路径上的节点数. 说明: 叶子节点是指没有子节点的节点. 示例: 给定二叉树 [3,9,20,null,null,15,7], 3 / \ 9  20 /  \ 15   7 返回它的最大深度 3 . 我的解答: 使用递归求二叉树的最大深度,想要求根节点的最大深度,需要求其左右两个节点中更大的深度+1,想要求左右两个节点的深度也是如此,代码如下:…
题目1 ID88 给你两个有序整数数组 nums1 和 nums2,请你将 nums2 合并到 nums1 中,使 num1 成为一个有序数组. 说明: 初始化 nums1 和 nums2 的元素数量分别为 m 和 n . 你可以假设 nums1 有足够的空间(空间大小大于或等于 m + n)来保存 nums2 中的元素. 示例: 输入: nums1 = [1,2,3,0,0,0], m = 3 nums2 = [2,5,6],       n = 3 输出: [1,2,2,3,5,6] 我的解…
scrapy爬虫的学习告一段落,又因为现在在学习数据结构,做题平台是lettcode:https://leetcode-cn.com/ 每周都要交一次做题的笔记,所以把相关代码和思路同时放在博客上记录 题目1 ID1 给定一个整数数组 nums 和一个目标值 target,请你在该数组中找出和为目标值的那 两个 整数,并返回他们的数组下标. 你可以假设每种输入只会对应一个答案.但是,你不能重复利用这个数组中同样的元素. 示例: 给定 nums = [2, 7, 11, 15], target =…
问题描述 Given two binary trees, write a function to check if they are equal or not. Two binary trees are considered equal if they are structurally identical and the nodes have the same value. 和Balanced Binary Tree那题很像.定义T(p)为以p为根的树,T(p) = T(q)需要符合两个条件:…
问题描述 Write a function to delete a node (except the tail) in a singly linked list, given only access to that node. Supposed the linked list is 1 -> 2 -> 3 -> 4 and you are given the third node with value 3, the linked list should become 1 -> 2…
标题 Maximum Depth of Binary Tree 描述 The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node. c++实现方法代码 1.递归实现,时间复杂度为O(n) 空间复杂度为O(logn) /** * Definition for binary tree * struct TreeNode { * int…
题目: Given a non-negative integer num, repeatedly add all its digits until the result has only one digit. For example: Given num = 38, the process is like: 3 + 8 = 11, 1 + 1 = 2. Since 2 has only one digit, return it. Follow up: Could you do it withou…
问题描述 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. 解决思路: 推荐算法: Moore votin…
1.整数反转 题目:给出一个 32 位的有符号整数,你需要将这个整数中每位上的数字进行反转. 思路:把最后的一位提取出来,放到新的容器前面,反复进行上面的操作,同时也要判断是否会导致溢出 class Solution { public: int reverse(int x) { ; ) { ; //提取最后一位 x /= ; //去掉最后一位 && (rev = INT_MAX / && pop > )) ; && (rev = INT_MIN / &…
原地算法:是一种使用小的,固定数量的额外之空间来转换资料的算法.当算法执行时,输入的资料通常会被要输出的部份覆盖掉. 范例:冒泡排序.选择排序.插入排序.希尔排序 (1)冒泡排序: 冒泡排序算法的原理如下: 比较相邻的元素.如果第一个比第二个大,就交换他们两个. 对每一对相邻元素做同样的工作,从开始第一对到结尾的最后一对.在这一点,最后的元素应该会是最大的数. 针对所有的元素重复以上的步骤,除了最后一个. 持续每次对越来越少的元素重复上面的步骤,直到没有任何一对数字需要比较 冒泡排序OC代码如下…
1  leetcode-69. x 的平方根   https://www.cnblogs.com/shoshana-kong/p/9745424.html 2. 3. 4. 5. 6.…
转自https://leetcode-cn.com/ 1.两数之和 给定一个整数数组 nums 和一个目标值 target,请你在该数组中找出和为目标值的那 两个 整数,并返回他们的数组下标. 你可以假设每种输入只会对应一个答案.但是,你不能重复利用这个数组中同样的元素. class Solution { public static int[] twoSum(int[] nums, int target) { int[] res = new int[2]; for(int i = 0;i<num…
题目1 ID112 给定一个二叉树和一个目标和,判断该树中是否存在根节点到叶子节点的路径,这条路径上所有节点值相加等于目标和. 说明: 叶子节点是指没有子节点的节点. 示例: 给定如下二叉树,以及目标和 sum = 22, 5 / \ 4   8 /   / \ 11  13  4 /  \      \ 7    2      1 返回 true, 因为存在目标和为 22 的根节点到叶子节点的路径 5->4->11->2. 我的解答: 最开始的版本是这样的: /** * Definit…
大家好,我是米洛,求三连!求关注测试开发坑货! 回顾 我们上一节已经写好了左侧数据表目录,今天继续完成sql编辑器的部分. 调研组件 monaco 因为我们的项目用的是React,市面上很多编辑器都是js编写,react提供了一层方便的封装. 比如我们在HTTP调试页面用的JSON编辑器,是以monaco为原型封装成的React组件. monaco呢,是微软开源的,大家熟悉的VsCode其实内部核心也是monaco. 优点是美观,专业,缺点是使用比较复杂. AceEditor 用过yapi的人都…
从明天开始,白天在实验室完成工作,晚上来图书馆换个环境去学习算法数据结构等计算机基础性的技能.在LeetCode这个平台上做题. 现在感觉自己在算法和数据机构这方面实在是太薄弱了,需要慢慢的捡起来来,要不然明年开始找工作就太没有竞争力了!所以要坚持刷Leetcode上的题目,慢慢找到学习算法和数据结构的感觉,只有这样,才不愧是计算机科班出生了.同时还是看看图书馆的漂亮妹子,何乐而不为呢~~~ 娃哈哈哈哈哈~~…
一直没有系统地学习过算法,不过算法确实是需要系统学习的.大二上学期,在导师的建议下开始学习数据结构,零零散散的一学期,有了链表.栈.队列.树.图等的概念.又看了下那几个经典的算法——贪心算法.分治算法.动态规划以及回溯算法.不过,都是知其一不知其二的一知半解.到最后,发现学到了一堆的一知半解,在学校课程开这门课时,却又是不得不再学一遍.学一样东西,又不全心全意地主动去把它学好,到最后只是花费了时间,却没真真学到东西.所以,不求学识有多广,但求所学的都精. 一个偶然的机会,让我在网上找到了一本社区…
Manacher算法学习笔记 DECLARATION 引用来源:https://www.cnblogs.com/grandyang/p/4475985.html CONTENT 用途:寻找一个字符串的最长回文子串 时间复杂度:O(N) 算法步骤: 1.添加特殊字符 由于回文串的长度可奇可偶,比如"bob"是奇数形式的回文,"noon"就是偶数形式的回文,马拉车算法的第一步是预处理,做法是在每一个字符的左右都加上一个特殊字符,比如加上'#',那么 bob -->…
想要学习算法.应付笔试或者应付面试手撕算法题,相信大部分人都会去刷 Leetcode,有读者问?如果我在 leetcode 坚持刷它个 500 道题,以后笔试/面试稳吗? 这里我说下我的个人看法,我认为不稳.下面说说为啥不稳以及算法题应该如何刷.如何学才比较好,当然,也会推荐自己学过的资料. 一.先说说笔试题 在刷 leetcode 的时候,你会发现,每道题的题意都很短,你只需要花十几秒的时间,就知道这道题是要你干嘛了,并且每道题所用道的算法思想都很明确,动态规划.递归.二分查找等,你可能很快就…
StringBuffer 学习 StringBuffer() 构造一个没有字符的字符串缓冲区,初始容量为16个字符. deleteCharAt(int index) 删除char在这个指定序列index指定的位置 charAt(int index) 返回char 在指定序列位置的值 insert(int offset, char c) 在此序列中插入char参数的字符串表示形式 length() 返回字符长度 toString() 返回字符串 LeetCode(1323) class Numbe…
题目:Given a linked list, reverse the nodes of a linked list k at a time and return its modified list. If the number of nodes is not a multiple of k then left-out nodes in the end should remain as it is. You may not alter the values in the nodes, only…
问题描述如下: Given a linked list, return the node where the cycle begins. If there is no cycle, return null. Follow up: Can you solve it without using extra space? 从问题来看,如果可以充分利用额外空间的话,这个题目是不难的,然而题目提出了一个要求,能否在不使用任何额外空间的情况下解决这个问题. 通过反复思考,我觉得这题类似于追击问题,可以用一个…
================================== LeetCode的一些算法题,都是自己做的,欢迎提出改进~~ LeetCode:http://oj.leetcode.com ================================== <Reverse Words in a String>-20140328 Given an input string, reverse the string word by word. For example, Given s =…