算法
小鹏残月
记录自己的成长
展开
-
Uva297 Quadtrees【递归建四分树】【例题6-11】
白书 例题6-11用四分树来表示一个黑白图像:最大的图为根,然后按照图中的方式编号,从左到右对应4个子结点。如果某子结点对应的区域全黑或者全白,则直接用一个黑结点或者白结点表示;如果既有黑又有白,则用一个灰结点表示,并且为这个区域递归建树。思路用一个buffer表示黑白表格,利用递归建树,每当遇见p(灰色)就往下递归四个节点,遇到f(黑色)就把buf[][]对应的位置设原创 2017-06-15 13:24:06 · 442 阅读 · 0 评论 -
leetcode_SortList
描述: Sort a linked list in O(n log n) time using constant space complexity.在O(n*log(n))的时间复杂度,常数级空间复杂度内对一个链表进行排序 采用归并排序,用快慢指针将链表分成两部分,最后合并两个链表./** * Definition for singly-linked list. * struct Lis原创 2017-07-30 04:53:48 · 322 阅读 · 0 评论 -
leetcode insertionSortList
描述: Sort a linked list using insertion sort.使用插入排序对一个链表进行排序普通的插入排序,时间复杂度O(n^2)class Solution {public: ListNode * insertionSortList(ListNode * head) { ListNode dummy(0); ListNode原创 2017-07-30 13:17:19 · 281 阅读 · 0 评论 -
LeetCode 2. Add Two Numbers
原题: You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and ret原创 2017-07-09 20:43:55 · 160 阅读 · 0 评论 -
LeetCode 1. 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 th原创 2017-07-09 12:15:28 · 153 阅读 · 0 评论