【Insertion Sorted List】cpp】的更多相关文章

题目: Sort a linked list using insertion sort. 代码: /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class Solution { public: ListNode* insertionSortList(ListNode…
题目: Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. Note:You may assume that nums1 has enough space (size that is greater or equal to m + n) to hold additional elements from nums2. The number of elements i…
题目: Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. 代码: /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ cla…
题目: 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. 代码: /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode…
题目: 第一次刷的时候漏掉了这道题. 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. 代码: /** * Definition for singly-linked lis…
题目: There are two sorted arrays A and B of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)). 代码: class Solution { public: double findMedianSortedArrays(int A[], int m, int B[]…
题目: Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2). You are given a target value to search. If found in the array return its index, otherwise return -1. You may assume no du…
题目: https://leetcode.com/problems/remove-duplicates-from-sorted-array/ Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length. Do not allocate extra space for another array, you must do…
题目: Given a sorted array 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 may assume no duplicates in the array. Here are few examples.[1,3,5,6], 5 → 2[1,3,5,6],…
题意: 给出老虎的起始点.方向和驴的起始点.方向.. 规定老虎和驴都不会走自己走过的方格,并且当没路走的时候,驴会右转,老虎会左转.. 当转了一次还没路走就会停下来.. 问他们有没有可能在某一格相遇.. 思路: 模拟,深搜.. 用类似时间戳的东西给方格标记上,表示某一秒正好走到该方格.. 最后遍历一下驴在某一格方格标记时间是否和老虎在该格标记的时间一样,一样代表正好做过这里了.. 还有一种情况就是老虎或驴一直停在那里,那就算不相等,也是可以的.. Tips: 我一直忘了老虎或驴停下来的情况,这样…