![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
数据结构与算法
hfsmurf
这个作者很懒,什么都没留下…
展开
-
LeetCode-M-Insertion Sort List
题意Sort a linked list using insertion sort.解法链表插入算法实现,记录已排好序段的表头和表尾,记录小于当前值的最大节点,注意三种情况:链表头插入链表尾插入链表中插入实现/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNod原创 2017-04-07 20:05:54 · 201 阅读 · 0 评论 -
LeetCode-M-Remove Duplicates from Sorted List II
题意Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list.For example, Given 1->2->3->3->4->4->5, return 1->2->5. Given 1->1->1-原创 2017-04-15 17:57:57 · 351 阅读 · 0 评论 -
LeetCode-M-Reorder List
题意Given a singly linked list L: L0→L1→…→Ln-1→Ln, reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→…You must do this in-place without altering the nodes’ values.For example, Given {1,2,3,4}, reorder it to {1,4,2,原创 2017-04-17 00:11:23 · 293 阅读 · 0 评论 -
LeetCode-E-Remove Linked List Elements
题意Remove all elements from a linked list of integers that have value val.Example Given: 1 –> 2 –> 6 –> 3 –> 4 –> 5 –> 6, val = 6 Return: 1 –> 2 –> 3 –> 4 –> 5Credits: Special thanks to @mithmatt for原创 2017-04-17 00:19:08 · 220 阅读 · 0 评论 -
LeetCode-M-Copy List with Random Pointe
题意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 of the list.Subscribe to see which companies aske原创 2017-04-17 00:42:51 · 203 阅读 · 0 评论 -
LeetCode-M-Jump Game
题意Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Determine if you a原创 2017-04-17 01:03:51 · 158 阅读 · 0 评论 -
LeetCode-M-Binary Tree Level Order Traversal
题意Given a binary tree, return the level order traversal of its nodes’ values. (ie, from left to right, level by level).For example: Given binary tree [3,9,20,null,null,15,7], 3 / \ 9 20 /原创 2017-04-22 22:42:47 · 220 阅读 · 0 评论 -
LeetCode-E-Two Sum
题意Given an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would have exactly one solution, and you may not use the same e原创 2017-04-22 23:22:08 · 218 阅读 · 0 评论 -
LeetCode-E-Two Sum II - Input array is sorted
题意Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers s原创 2017-04-22 23:32:14 · 507 阅读 · 0 评论 -
LeetCode-M-Binary Tree Zigzag Level Order Traversal
题意Given a binary tree, return the zigzag level order traversal of its nodes’ values. (ie, from left to right, then right to left for the next level and alternate between).For example: Given binary tre原创 2017-04-23 00:13:31 · 175 阅读 · 0 评论 -
LeetCode-E-Isomorphic Strings
题意Given two strings s and t, determine if they are isomorphic.Two strings are isomorphic if the characters in s can be replaced to get t.All occurrences of a character must be replaced with another cha原创 2017-04-23 00:40:56 · 236 阅读 · 0 评论 -
LeetCode-M-Unique Binary Search Trees
题意Given n, how many structurally unique BST’s (binary search trees) that store values 1…n?For example, Given n = 3, there are a total of 5 unique BST’s. 1 3 3 2 1 \ /原创 2017-04-23 12:19:32 · 160 阅读 · 0 评论 -
LeetCode-M-Unique Binary Search Trees II
题意Given an integer n, generate all structurally unique BST’s (binary search trees) that store values 1…n.For example, Given n = 3, your program should return all 5 unique BST’s shown below. 1原创 2017-04-23 12:27:58 · 202 阅读 · 0 评论 -
LeetCode-E-Palindrome Linked List
题意Given a singly linked list, determine if it is a palindrome.Follow up: Could you do it in O(n) time and O(1) space?Subscribe to see which companies asked this question.Show Tags Show Similar Proble原创 2017-05-14 18:51:00 · 152 阅读 · 0 评论 -
LeetCode-E- Palindrome Number
题意Determine whether an integer is a palindrome. Do this without extra space.click to show spoilers.Subscribe to see which companies asked this question.解法实现class Solution {public: bool isPalindrom原创 2017-05-14 18:53:21 · 206 阅读 · 0 评论 -
LeetCode-E-Remove Duplicates from Sorted List
题意Given a sorted linked list, delete all duplicates such that each element appear only once.For example, Given 1->1->2, return 1->2. Given 1->1->2->3->3, return 1->2->3.Subscribe to see which compani原创 2017-04-15 17:12:52 · 241 阅读 · 0 评论 -
LeetCode - E- Min Stack
题意Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.push(x) – Push element x onto stack. pop() – Removes the element on top of the stack. top() – Get th原创 2017-04-14 19:26:51 · 217 阅读 · 0 评论 -
LeetCode-E-Fizz Buzz
题目Write a program that outputs the string representation of numbers from 1 to n.But for multiples of three it should output “Fizz” instead of the number and for the multiples of five output “Buzz”. For原创 2017-04-06 20:47:03 · 320 阅读 · 0 评论 -
LeetCode-E-Single Number
题目Given an array of integers, every element appears twice except for one. Find that single one.Note: Your algorithm should have a linear runtime complexity. Could you implement it without using extra原创 2017-04-06 20:43:34 · 285 阅读 · 0 评论 -
LeetCode-E-Same Tree
题目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.解法递归实现:均为null,返回原创 2017-04-06 20:37:09 · 270 阅读 · 0 评论 -
LeetCode-E-Delete Node in a Linked List
题目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,原创 2017-04-06 20:41:09 · 178 阅读 · 0 评论 -
LeetCode-M-Sort Colors
题意Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue.Here, we will use the integers 0,原创 2017-04-09 13:42:58 · 229 阅读 · 0 评论 -
LeetCode-M-Single Element in a Sorted Array
题意Given a sorted array consisting of only integers where every element appears twice except for one element which appears once. Find this single element that appears only once.Example 1:Input: [1,1,2,原创 2017-04-09 14:50:47 · 212 阅读 · 0 评论 -
LeetCode - M- Rotate List
LeetCode - Rotate List - 翻转链表原创 2017-04-05 23:48:53 · 194 阅读 · 0 评论 -
LeetCode - E - Reverse Integer
题意Reverse digits of an integer.Example1: x = 123, return 321 Example2: x = -123, return -321click to show spoilers.Note: The input is assumed to be a 32-bit signed integer. Your function should retur原创 2017-04-09 19:00:34 · 160 阅读 · 0 评论 -
LeetCode - E - Reverse Linked List
题意Reverse a singly linked list.click to show more hints.Subscribe to see which companies asked this question.解法将当前元素插入到头节点之前实现/** * Definition for singly-linked list. * struct ListNode { * int v原创 2017-04-09 19:16:50 · 154 阅读 · 0 评论 -
LeetCode - M - Reverse Linked List II
题意Reverse a linked list from position m to n. Do it in-place and in one-pass.For example: Given 1->2->3->4->5->NULL, m = 2 and n = 4,return 1->4->3->2->5->NULL.Note: Given m, n satisfy the following原创 2017-04-09 19:47:45 · 179 阅读 · 0 评论 -
LeetCode - M - 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 use only constant space. You may原创 2017-04-09 20:00:32 · 146 阅读 · 0 评论 -
LeetCode - H - Reverse Nodes in k-Group
题意Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.k is a positive integer and is less than or equal to the length of the linked list. If the number of n原创 2017-04-09 20:37:53 · 275 阅读 · 0 评论 -
LeetCode - M - Evaluate Reverse Polish Notation
题意Evaluate the value of an arithmetic expression in Reverse Polish Notation.Valid operators are +, -, *, /. Each operand may be an integer or another expression.Some examples: ["2", "1", "+", "3", "*原创 2017-04-09 21:15:13 · 190 阅读 · 0 评论 -
LeetCode-E-Valid Palindrome
题意Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example, “A man, a plan, a canal: Panama” is a palindrome. “race a car” is not a pal原创 2017-05-14 18:55:22 · 185 阅读 · 0 评论