leetcode
文章平均质量分 74
SegmentFault_
这个作者很懒,什么都没留下…
展开
-
LeetCode Rotate Function
Given an array of integers A and let n to be its length. Assume Bk to be an array obtained by rotating the array A k positions clock-wise, we define a "rotation function" F on A as follow:原创 2016-09-24 11:41:06 · 438 阅读 · 0 评论 -
LeetCode Pascal's Triangle II
Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Return [1,3,3,1]. Pascal三角形也叫杨辉三角形。杨辉三角形按如下性质进行排列: 1 1原创 2016-09-24 19:51:05 · 414 阅读 · 0 评论 -
LeetCode Invert Binary Tree
Invert a binary tree. 4 / \ 2 7 / \ / \ 1 3 6 9 to 4 / \ 7 2 / \ / \ 9 6 3 1 反转二叉树,首先采用递归的方式。先遍历作左子树,当指针指向NULL时,返回,赋值给tmp。接着遍历右子树,指向NULL,返回,并将该返回值赋原创 2016-09-25 16:09:41 · 425 阅读 · 0 评论 -
LeetCode Construct Binary Tree from Traversal
1.Construct Binary Tree from Preorder and Inorder Traversal 根据二叉树前序遍历和中序遍历构造一颗二叉树。 现在有前序遍历4213769,中序遍历为1234679。根据前序和中序遍历的概念,构造一棵二叉树如下步骤: (1) 设前序遍历的下标为prebegin = 0,preend = preorder.size() - 1。中序遍历下原创 2016-09-26 10:53:56 · 424 阅读 · 0 评论 -
LeetCode Odd Even Linked List
Given a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node number and not the value in the nodes. You should try to do it in原创 2016-10-06 23:51:08 · 479 阅读 · 0 评论 -
LeetCode Sort List(链表快速排序)
Sort a linked list in O(n log n) time using constant space complexity. 看到O(n log n)这个复杂度就想到了快速排序法。快速排序法主要思想为取一个基准点,采用交换+分治法完成快速排序。 对于单链表的快速排序,不能从后面开始遍历,因为根据后继找不到其前驱。因此采用以下步骤: 1.取每次的头节点为基准节点,然后将这个原创 2016-10-08 17:17:30 · 1996 阅读 · 1 评论