Skip to content

Instantly share code, notes, and snippets.

@linnet8989
linnet8989 / Depth First.txt
Last active March 17, 2017 07:15
深度优先搜索 代码编写指引
函数(参数:节点)
{
定义:一个栈
初始化:节点入栈
搜索过程:
循环(当栈为不为空时继续)
{
1. 栈顶出栈
2. 此处插入验证(可在此处退出)条件
3. 将出栈节点的子节点加入栈
@linnet8989
linnet8989 / Breadth First.txt
Last active March 17, 2017 06:50
广度优先搜索 代码编写指引
函数(参数:节点)
{
定义:一个队列
初始化:节点入队
搜索过程:
循环(当队列为不为空时继续)
{
1. 队首出队
2. 此处插入验证(可在此处退出)条件
3. 将出队节点的子节点加入队列
@linnet8989
linnet8989 / leetcode5.cs
Created February 25, 2017 14:17
5. Longest Palindromic Substring
public class Solution
{
public string LongestPalindrome(string s)
{
bool isPalindromic = false;
if(s.Length==0){
return "";
}
for (int i = s.Length; i > 0; i--)
{
@linnet8989
linnet8989 / leetcode3.cs
Created February 22, 2017 07:45
3. Longest Substring Without Repeating Characters
public class Solution
{
public int LengthOfLongestSubstring(string s)
{
int subLength = 0;
int r = 0;
int repetitionIndex;
int start = 0;
for (int i = 0; i < s.Length; i++)
{
@linnet8989
linnet8989 / leetcode2.cs
Created February 21, 2017 11:56
2. Add Two Numbers
public class ListNode {
public int val;
public ListNode next;
public ListNode(int x) { val = x; }
}
public class Solution
{
public ListNode AddTwoNumbers(ListNode l1, ListNode l2)
@linnet8989
linnet8989 / leetcode1.cs
Last active February 21, 2017 11:56
1. Two Sum
using System.Collections;
public class Solution
{
public int[] TwoSum(int[] nums, int target)
{
int pair;
Hashtable ht = new Hashtable();
for (int i = 0; i < nums.Length; i++)
{
# 树
## 树状数组(Binery Index Tree)
### 简介
其初衷是解决数据压缩里的累积频率(Cumulative Frequency)的计算问题,现多用于高效计算数列的前缀和, 区间和。
它可以以 {\displaystyle O(\log n)} O(\log n)的时间得到任意前缀和 {\displaystyle \sum _{i=1}^{j}a[i],1<=j<=N} {\displaystyle \sum _{i=1}^{j}a[i],1<=j<=N},并同时支持在 {\displaystyle O(\log n)} O(\log n)时间内支持动态单点值的修改。空间复杂度 {\displaystyle O(n)} O(n)。
### 基本操作