随笔分类 -  Leetcode

摘要:反转一个单链表。 Reverse a singly linked list. 示例: 进阶: 你可以迭代或递归地反转链表。你能否用两种方法解决这道题? Follow up: A linked list can be reversed either iteratively or recursively 阅读全文
posted @ 2019-07-22 10:32 爱写Bug 阅读(130) 评论(0) 推荐(0)
摘要:​给出两个 非空 的链表用来表示两个非负的整数。其中,它们各自的位数是按照 逆序 的方式存储的,并且它们的每个节点只能存储 一位 数字。如果,我们将这两个数相加起来,则会返回一个新的链表来表示它们的和。 You are given two non empty linked lists represe 阅读全文
posted @ 2019-07-21 12:21 爱写Bug 阅读(136) 评论(0) 推荐(0)
摘要:​给定一个单链表,把所有的奇数节点和偶数节点分别排在一起。请注意,这里的奇数节点和偶数节点指的是节点编号的奇偶性,而不是节点的值的奇偶性。 请尝试使用原地算法完成。你的算法的空间复杂度应为 O(1),时间复杂度应为 O(nodes),nodes 为节点总数。 Given a singly linke 阅读全文
posted @ 2019-07-20 09:50 爱写Bug 阅读(150) 评论(0) 推荐(0)
摘要:爱写Bug(ID:iCodeBugs) 编写一个程序,找到两个单链表相交的起始节点。 Write a program to find the node at which the intersection of two singly linked lists begins. 如下面的两个链表 : 在节 阅读全文
posted @ 2019-07-19 13:10 爱写Bug 阅读(112) 评论(0) 推荐(0)
摘要:删除链表中等于给定值 val 的所有节点。 Remove all elements from a linked list of integers that have value val . 示例: 解题思路: 两种方法,一种是迭代法,从第一个节点开始,遇到值相同的节点就将其删除。链表的删除操作是直接 阅读全文
posted @ 2019-07-18 10:16 爱写Bug 阅读(165) 评论(0) 推荐(0)
摘要:给定一个链表,返回链表开始入环的第一个节点。 如果链表无环,则返回 。 为了表示给定链表中的环,我们使用整数 来表示链表尾连接到链表中的位置(索引从 0 开始)。 如果 是 ,则在该链表中没有环。 说明: 不允许修改给定的链表。 Given a linked list, return the nod 阅读全文
posted @ 2019-07-17 12:11 爱写Bug 阅读(133) 评论(0) 推荐(0)
摘要:给定一个链表,判断链表中是否有环。 为了表示给定链表中的环,我们使用整数 来表示链表尾连接到链表中的位置(索引从 0 开始)。 如果 是 ,则在该链表中没有环。 Given a linked list, determine if it has a cycle in it. To represent 阅读全文
posted @ 2019-07-16 10:14 爱写Bug 阅读(164) 评论(0) 推荐(0)
摘要:给定一个排序数组,你需要在 原地 删除重复出现的元素,使得每个元素只出现一次,返回移除后数组的新长度。 不要使用额外的数组空间,你必须在 原地修改输入数组 并在使用 O(1) 额外空间的条件下完成。 Given a sorted array nums , remove the duplicates 阅读全文
posted @ 2019-07-15 10:22 爱写Bug 阅读(127) 评论(0) 推荐(0)
摘要:爱写bug (ID:iCodeBugs) 设计链表的实现。您可以选择使用单链表或双链表。单链表中的节点应该具有两个属性: 和 。`val next prev` 以指示链表中的上一个节点。假设链表中的所有节点都是 0 index 的。 在链表类中实现这些功能: get(index):获取链表中第 个节 阅读全文
posted @ 2019-07-14 11:08 爱写Bug 阅读(207) 评论(0) 推荐(0)
摘要:给定一个数组 ,编写一个函数将所有 移动到数组的末尾,同时保持非零元素的相对顺序。 Given an array , write a function to move all 's to the end of it while maintaining the relative order of th 阅读全文
posted @ 2019-07-13 11:50 爱写Bug 阅读(161) 评论(0) 推荐(0)
摘要:公众号:爱写bug(ID:icodebugs) 给定一个字符串,你需要反转字符串中每个单词的字符顺序,同时仍保留空格和单词的初始顺序。 Given a string, you need to reverse the order of characters in each word within a 阅读全文
posted @ 2019-07-12 10:21 爱写Bug 阅读(112) 评论(0) 推荐(0)
摘要:公众号:爱写bug(ID:icodebugs) 翻转字符串里的单词 Given an input string, reverse the string word by word. 示例 1: 示例 2: 示例 3: 说明: 无空格字符构成一个单词。 输入字符串可以在前面或者后面包含多余的空格,但是反 阅读全文
posted @ 2019-07-11 12:43 爱写Bug 阅读(725) 评论(0) 推荐(0)
摘要:公众号: 爱写bug(ID:icodebugs) 作者:爱写bug 给定一个含有 n 个正整数的数组和一个正整数 s , 找出该数组中满足其和 ≥ s 的长度最小的连续子数组 。 如果不存在符合条件的连续子数组,返回 0。 Given an array of n positive integers 阅读全文
posted @ 2019-07-10 13:25 爱写Bug 阅读(163) 评论(0) 推荐(0)
摘要:公众号:爱写bug(ID:icodebugs) 给定一个数组,将数组中的元素向右移动 k 个位置,其中 k 是非负数。 Given an array, rotate the array to the right by k steps, where k is non negative. 示例 1: 示 阅读全文
posted @ 2019-07-09 12:37 爱写Bug 阅读(140) 评论(0) 推荐(0)
摘要:爱写bug(ID:icodebugs) 作者:爱写bug 实现 "strStr()" 函数。 给定一个 haystack 字符串和一个 needle 字符串,在 haystack 字符串中找出 needle 字符串出现的第一个位置 (从0开始)。如果不存在,则返回 1 。 Implement "st 阅读全文
posted @ 2019-07-08 19:48 爱写Bug 阅读(182) 评论(0) 推荐(0)
摘要:公众号:爱写bug(ID:icodebugs) 作者:爱写bug 给定一个非负索引 k ,其中 k ≤ 33,返回杨辉三角的第 k 行。 Given a non negative index k where k ≤ 33, return the k th index row of the Pasca 阅读全文
posted @ 2019-07-07 10:18 爱写Bug 阅读(135) 评论(0) 推荐(0)
摘要:公众号: 爱写bug(ID:icodebugs) 给定一个已按照 升序排列 的有序数组,找到两个数使得它们相加之和等于目标数。 函数应该返回这两个下标值 index1 和 index2,其中 index1 必须小于 index2 。 说明: 返回的下标值(index1 和 index2)不是从零开始 阅读全文
posted @ 2019-07-06 14:54 爱写Bug 阅读(133) 评论(0) 推荐(0)
摘要:算法是一个程序的灵魂 公众号:爱写bug(ID:icodebugs) 作者:爱写bug 给定一个含有 n 个正整数的数组和一个正整数 s , 找出该数组中满足其和 ≥ s 的长度最小的连续子数组 。 如果不存在符合条件的连续子数组,返回 0。 Given an array of n positive 阅读全文
posted @ 2019-07-04 14:35 爱写Bug 阅读(118) 评论(0) 推荐(0)
摘要:文章全部来自公众号:爱写bug 算法是一个程序的灵魂。 Given an array of 2n integers, your task is to group these integers into n pairs of integer, say (a1, b1), (a2, b2), ..., 阅读全文
posted @ 2019-07-03 19:39 爱写Bug 阅读(166) 评论(0) 推荐(0)
摘要:公众号:爱写bug 给定一个数组 nums 和一个值 val ,你需要 原地 移除所有数值等于 val 的元素,返回移除后数组的新长度。 不要使用额外的数组空间,你必须在 原地修改输入数组 并在使用 O(1) 额外空间的条件下完成。 元素的顺序可以改变。你不需要考虑数组中超出新长度后面的元素。 Gi 阅读全文
posted @ 2019-07-02 13:26 爱写Bug 阅读(233) 评论(0) 推荐(0)