摘要:
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading;using System.Threading.Tasks;namespace Leetco... 阅读全文
随笔分类 - 数据结构和算法
LeetCode:Flatten Binary Tree to Linked List
2015-08-10 21:59 by F_Code, 119 阅读, 收藏,
摘要:
//LeetCode:https://leetcode.com/problems/flatten-binary-tree-to-linked-list/ //Flatten Binary Tree to Linked List 114 //前序遍历,last是链表最后一个节点,然后使用前序遍历,遍历一个节点就在last插入这个节点 //在遍历的过程中树的结构会被打乱... 阅读全文
LeetCode:Validate Binary Search Tree
2015-08-08 20:48 by F_Code, 141 阅读, 收藏,
摘要:
//二叉树搜索树定义,中序遍历的思想 class ValidateBinarySearchTree { private TreeNode pre=null; public bool IsValidBST(TreeNode root) { if (root == null) ... 阅读全文
两道关于前缀和的算法题
2015-06-22 21:56 by F_Code, 2856 阅读, 收藏,
摘要:
今天看到了两道有关于前缀和应用的的算法题,解法挺巧妙的,分享给大家。在这里直接放上我的代码,题目和注释在代码解释的都非常清楚。 1 /* 2 * 题目描述:给定一个数组a[N],我们希望构造数组b[N], 3 * 其中b[i]=a[0]*a[1]*...*a[N-1]/a... 阅读全文
LeetCode
2015-06-06 21:19 by F_Code, 382 阅读, 收藏,
摘要:
LeetCode上第164题,https://leetcode.com/problems/maximum-gap/。LeetCode上的题都是挺有意思的,不管是不是为了面试个人觉得都值得去刷刷,比如这题使用桶排序巧妙地用O(n)的时间解决了这道题,很有意思。 1 using System; 2 us... 阅读全文
LeetCode FindMinimuminRotatedSorteArray &&FindMinimuminRotatedSorteArray2
2015-05-19 10:52 by F_Code, 195 阅读, 收藏,
摘要:
LeetCode上这两道题主要是使用二分搜索解决,是二分搜索算法的一个应用,根据条件每次舍弃一半,保留一半。首先第一题:FindMinimuminRotatedSorteArray(时间复杂度为二分算法的时间复杂度O(logN)) 1 using System; 2 using System.Col... 阅读全文