随笔分类 - Leetcode+题
摘要:Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 to 3999. 思路:有关罗马数字的相关知识可见博客Integer to roman。从左往右遍历字
阅读全文
摘要:Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 to 3999. 题意:将整数转换成罗马数字,这里就需要对什么是罗马数字有一些了解。一下部分摘选于百度
阅读全文
摘要:Given a linked list, remove the n th node from the end of list and return its head. For example, Note: Given n will always be valid.Try to do this in
阅读全文
摘要:Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. 思路:这题最容易想到的是,(假设有k个链表)链表1、2合并,然后其结果12和3合并,以此类推,最后是1
阅读全文
摘要:Given a linked list, swap every two adjacent nodes and return its head. For example,Given1->2->3->4, you should return the list as2->1->4->3. Your alg
阅读全文
摘要: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 l
阅读全文
摘要:You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single
阅读全文
摘要:Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x. You should preserve the
阅读全文
摘要:Reverse a linked list from position m to n. Do it in-place and in one-pass. For example:Given1->2->3->4->5->NULL, m = 2 and n = 4, return1->4->3->2->5
阅读全文
摘要:Given a list, rotate the list to the right by k places, where k is non-negative. For example:Given1->2->3->4->5->NULLand k =2,return4->5->1->2->3->NUL
阅读全文
摘要:Given a linked list, return the node where the cycle begins. If there is no cycle, returnnull. Follow up:Can you solve it without using extra space? 题
阅读全文
摘要:Given a linked list, determine if it has a cycle in it. Follow up:Can you solve it without using extra space? 判断链表中是否有环,不能用额外的空间,可以使用快慢指针,慢指针一次走一步,快指针
阅读全文
摘要:Given a singly linked list L: L 0→L 1→…→L n-1→L n,reorder it to: L 0→L n →L 1→L n-1→L 2→L n-2→… You must do this in-place without altering the nodes'
阅读全文
摘要:Sort a linked list in O(n log n) time using constant space complexity. 时间复杂度为O(nlogn),可以想到归并排序、快排、桶排序。 思路:使用归并排序,整体可以分为两体,一、构造两个已排序的子链表;二、将子链表合并。针对第一部
阅读全文
摘要:恢复内容开始 Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST. 题目要求:转成高度平衡的二叉搜索树。 高度平衡的二叉搜索树:i)左
阅读全文
摘要:A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null. Return a deep copy
阅读全文
摘要:Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list. For example,Given1->2-
阅读全文
摘要:Given a sorted linked list, delete all duplicates such that each element appear only once. For example,Given1->1->2, return1->2.Given1->1->2->3->3, re
阅读全文
摘要:Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists. 题意:合并两个排
阅读全文
摘要:Two elements of a binary search tree (BST) are swapped by mistake. Recover the tree without changing its structure. Note: A solution using O(n ) space
阅读全文

浙公网安备 33010602011771号