`
cozilla
  • 浏览: 89288 次
  • 性别: Icon_minigender_1
  • 来自: 南京
社区版块
存档分类
最新评论
文章列表
Insert Interval Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary). You may assume that the intervals were initially sorted according to their start times. Example 1:Given intervals [1,3],[6,9], insert and merge 
Implement strStr() Implement strStr(). Returns a pointer to the first occurrence of needle in haystack, or null if needle is not part of haystack. 方法:KMP 正好趁这个题目温习了一下KMP字符串匹配。母串S, 模式串P KMP算法是利用模式串P本身的特性来降低复杂度。通过next函数or覆盖函数来优化。 本质上,next函数/覆盖函数是overlap[i]是求出P[0~i]内的最大的前缀P[0~i-x]和后缀P[x~i]的长度 ...
First Missing Positive Given an unsorted integer array, find the first missing positive integer. For example,Given [1,2,0] return 3,and [3,4,-1,1] return 
Divide Two Integers Divide two integers without using multiplication, division and mod operator. 不用*, /, %来实现除法。 注意:1.正负号;2.INT_min=-2147483648,变为正数越界。 const int INTMIN = -2147483648; class Solution { public: int divide(int dividend, int divisor) { if (divisor == INTMI ...
Given a string S and a string T, count the number of distinct subsequences of T in S. A subsequence of a string is a new string which is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (ie, &qu ...
  Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, 
本文LeetCode(http://www.leetcode.com/onlinejudge)内的binary tree travel,包含3个: 1). Binary Tree Inorder Traversal 2). Binary Tree Level Order Traversal 3). Binary Tree Maximum Path Sum   1). Binary Tree Inorder Traversal   递归很简单;常规做法。非递归版本用stack保存,right,val,left依次压入。   class Solution { public: ...
1.   Say you have an array for which the ith element is the price of a given stock on day i. If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the stock), design an algorithm to find the maximum profit. 复杂度:O(N)   class Solution { public: ...
个人博客:http://coolgo-zq.appspot.com/     前段时间,忽然想到做一个关于“六度空间”的应用-找出两个不认识人的联系。在自己经过一些准备以后,于是,故事开始了。 考虑到数据的敏感性,就不提供代码和数据的下载。在这 ...
这段时间看A*,然后就把经典问题八数码做了一遍。以前听朋友说过,自己实现的时候还是学到了不少东西。   八数码问题主要思想: 1.将3×3的table用一维字符串表示 2.一维字符串是共有9!个,因此用hash来散列 3.把问题转换为寻路问题,起点是初始状态,终点是目标状态,每移一下,相当于走了一步   我觉得八数码问题当中的估计函数(启发函数)是一个亮点:我自己想到的是用当前的字符串与 目标字符串比较,h=不在位的数。这个启发函数虽然不是很好,但是还是能做出来的。   同样,八数码解的判定也是个亮点:逆序数。转成一维以后,计算出不包含0的逆序数,然后奇偶性判断。这个是 ...
这几天看了A*搜索的寻路算法,发现精华在于f = g + h,我觉得难点在于如何确定估价函数的h。 本段代码是迷宫找路。估价函数:h是用的曼哈顿距离 贴出自己的代码,分享一下。可以讨论 文章会附上:代码.rar和测试     import java.util.PriorityQueue; import java.util.Scanner; public class AStar { private int stepx[] = { 0, 1, 1, 1, 0, -1, -1, -1 };// 第一个是上,顺时针 private int stepy[] = { 1, ...
Ibatis2.3.4、spring2.0、mysql5.1、mysql-connect-java-5.0.4-bin.jar。 1、Mysql准备数据(use itcast数据库) mysql> create  table  student(id int  primary  key  auto_increment, firstname varchar (20), lastname varchar (20)); 2、准备POJO类 package  cn.itcast;public  class  Student 
前段时间进一步了解webServer,因此听老大的话,自己实现了一个。代码如下   WebServer类 import java.io.IOException; import java.net.ServerSocket; import java.net.Socket; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; public class WebServer { public static void main(String[] args) ...
Global site tag (gtag.js) - Google Analytics