![](https://img-blog.csdnimg.cn/20190918140037908.png?x-oss-process=image/resize,m_fixed,h_224,w_224)
LeetCode——20天算法入门
文章平均质量分 84
来自Leetcode学习计划中的20 天「算法」刷题计划
「已注销」
这个作者很懒,什么都没留下…
展开
-
557. (Reverse Words in a String III)反转字符串中的单词 III
题目:解题思路:Python代码Java代码C++代码复杂度分析题目:Given a string s, reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order.给定一个字符串s,将句子中每个单词的字符顺序颠倒,同时仍然保留空格和最初的单词顺序。Example 1:Input: s = “Let’s take Le.原创 2021-09-12 10:03:35 · 240 阅读 · 2 评论 -
876. (Middle of the Linked List)链表的中间结点
题目:Given the head of a singly linked list, return the middle node of the linked list.If there are two middle nodes, return the second middle node.给定一个头结点为 head 的非空单链表,返回链表的中间结点。如果有两个中间结点,则返回第二个中间结点Example 1:Input: head = [1,2,3,4,5]Output: [3,4,5]原创 2021-08-26 16:26:14 · 278 阅读 · 17 评论 -
344. (Reverse String)反转字符串
题目:解题思路:Python代码Java代码C++代码复杂度分析题目:Write a function that reverses a string. The input string is given as an array of characters s.写一个反转字符串的函数。输入字符串以字符数组的形式给出。Example 1:Input: s = [“h”,“e”,“l”,“l”,“o”]Output: [“o”,“l”,“l”,“e”,“h”]示例 1:输入:[“h”,“e”,“.原创 2021-08-20 11:59:49 · 522 阅读 · 17 评论 -
167. (Two Sum II - Input array is sorted)两数之和 II - 输入有序数组
题目:解题思路:Python代码Java代码C++代码复杂度分析题目:Given an array of integers numbers that is already sorted in non-decreasing order, find two numbers such that they add up to a specific target number.Return the indices of the two numbers (1-indexed) as an integer arr.原创 2021-08-20 11:15:11 · 127 阅读 · 2 评论 -
283. (Move Zeroes)移动零
题目:解题思路:Python代码Java代码C++代码复杂度分析题目:Given an integer array nums, move all 0’s to the end of it while maintaining the relative order of the non-zero elements.Note that you must do this in-place without making a copy of the array.给定一个整数数组nums,在保持非零元素的相对顺.原创 2021-08-19 23:26:05 · 242 阅读 · 5 评论 -
977. (Squares of a Sorted Array)有序数组的平方
题目:解题思路:Python代码Java代码C++代码复杂度分析题目:Given an integer array nums sorted in non-decreasing order, return an array of the squares of each number sorted in non-decreasing order.给你一个按非递减顺序排序的整数数组 nums,返回每个数字的平方组成的新数组,要求也按非递减顺序排序。Example 1:Input: nums = [-4.原创 2021-08-19 22:42:19 · 193 阅读 · 3 评论 -
35. (Search Insert Position)搜索插入位置
题目:Given a sorted array of distinct integers 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 must write an algorithm with O(log n) runtime complexity.给定一个排序数组和一个目标值原创 2021-08-18 19:56:51 · 367 阅读 · 9 评论 -
278. (First Bad Version)第一个错误的版本
题目:You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality check. Since each version is developed based on the previous version, all the versions after a bad vers原创 2021-08-18 10:06:13 · 318 阅读 · 14 评论 -
704. (Binary Search)二分查找
题目:Given an array of integers nums which is sorted in ascending order, and an integer target, write a function to search target in nums. If target exists, then return its index. Otherwise, return -1.You must write an algorithm with O(log n) runtime compl原创 2021-08-17 20:43:14 · 264 阅读 · 30 评论