0%

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package com.tradingplatform.dto;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
* 用于操作时间运算的类
* @author cc
*
*/
public class DateOperationDto {
/**
* 得到几天前的时间
* @param d
* @param day
* @return
*/
public Date getDateBefore(Date d, int day) {
Calendar now = Calendar.getInstance();
now.setTime(d);
now.set(Calendar.DATE, now.get(Calendar.DATE) - day);
return now.getTime();
}

/**
* 得到几天后的时间
* @param d
* @param day
* @return
*/
public Date getDateAfter(Date d, int day) {
Calendar now = Calendar.getInstance();
now.setTime(d);
now.set(Calendar.DATE, now.get(Calendar.DATE) + day);
return now.getTime();
}
public static void main(String[] args) throws ParseException {

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date=new Date();
System.out.println(sdf.format(date));
Date addDate=new Date(date.getTime()+600000);
System.out.println(sdf.format(addDate));
//2017-05-07 10:32:33
String oldTime="2017-05-07 10:35:34";
Date oldDate=sdf.parse(oldTime);
System.out.println(sdf.format(oldDate));
Date newTime=new Date(oldDate.getTime()+600000);
Date newTime1=new Date(oldDate.getTime()-10000);
System.out.println(newTime);
System.out.println(sdf.format(newTime));
System.out.println(sdf.format(newTime1));

}
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package com.tradingplatform.dto;

import java.util.List;

/**
* 分页原理页面传送数据的Dto
* @param <T>:传送的数据的类型
*/
public class PageJumpDataDto<T> {
private int currentPage=1; //当前页
private int totalPage=0; //总共页
private int totalRecord=0; //总记录数
private List<T> listData; //数据
private int pageSize=6; //每页记录数

public PageJumpDataDto() {}

public PageJumpDataDto(int currentPage, int totalPage, int totalRecord, List<T> listData, int pageSize) {
super();
this.currentPage = currentPage;
this.totalPage = totalPage;
this.totalRecord = totalRecord;
this.listData = listData;
this.pageSize = pageSize;
}

public PageJumpDataDto(int currentPage, List<T> listData) {
if(listData==null) return;
this.totalRecord = listData.size();
//得到总页数
this.totalPage = this.totalRecord/this.pageSize;
if(this.totalRecord%this.pageSize!=0) this.totalPage+=1;
//得到当前页数
if(this.totalPage<currentPage){
this.currentPage=this.totalPage;
}else{
this.currentPage=currentPage;
}
if(this.currentPage<1) this.currentPage=1;
//得到截取的展示数据
int begin=this.pageSize*(this.currentPage-1);
int end= (this.pageSize*this.currentPage)>this.totalRecord?this.totalRecord:(this.pageSize*this.currentPage);
this.listData=listData.subList(begin, end);
}

public PageJumpDataDto(int currentPage, List<T> listData,int pageSize) {
if(listData==null) return;
this.pageSize=pageSize;
this.totalRecord = listData.size();
//得到总页数
this.totalPage = this.totalRecord/this.pageSize;
if(this.totalRecord%this.pageSize!=0) this.totalPage+=1;
//得到当前页数
if(this.totalPage<currentPage){
this.currentPage=this.totalPage;
}else{
this.currentPage=currentPage;
}
if(this.currentPage<1) this.currentPage=1;
//得到截取的展示数据
int begin=this.pageSize*(this.currentPage-1);
int end= (this.pageSize*this.currentPage)>this.totalRecord?this.totalRecord:(this.pageSize*this.currentPage);
this.listData=listData.subList(begin, end);
}

public int getCurrentPage() {
return currentPage;
}
public void setCurrentPage(int currentPage) {
this.currentPage = currentPage;
}
public int getTotalPage() {
return totalPage;
}
public void setTotalPage(int totalPage) {
this.totalPage = totalPage;
}
public int getTotalRecord() {
return totalRecord;
}
public void setTotalRecord(int totalRecord) {
this.totalRecord = totalRecord;
}

public List<T> getListData() {
return listData;
}

public void setListData(List<T> listData) {
this.listData = listData;
}

public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}

}

下述转换属于字符串流,需要附带头文件

1
#include<<sstream>

int 转string

1
2
3
4
5
int number=100;
string str;
stringstream buffer;
buffer<<number;
buffer>>str;</span>

string转int

1
2
3
4
5
int number;
string str="666"
stringstream buffer;
buffer<<str;
buffer>>number;</span>

三指针法遍历,一次遍历则完成反转:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
ListNode* ReverseList(ListNode* pHead) {
//no node
if(pHead==nullptr) return pHead;
ListNode* pre=nullptr,*mid=pHead,*last=nullptr;
//more node/single node
while(mid->next!=nullptr){
//confirm the location
last=mid->next;
mid->next=pre; pre=mid;mid=last;
}
mid->next=pre;
pHead=mid;
return pHead;
}

题目描述

Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.

Read more »

解法一

递归思路,需要重新创建一个链表,空间复杂度O(1)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
ListNode* Merge(ListNode* pHead1, ListNode* pHead2)
{
if(pHead1==nullptr) return pHead2;
if(pHead2==nullptr) return pHead1;
ListNode* list;
if(pHead1->val>pHead2->val){
list=pHead2;
list->next=Merge(pHead1,pHead2->next);
}
else{
list=pHead1;
list->next=Merge(pHead1->next,pHead2);
}
return list;
}
Read more »

JUnit4官网

http://junit.org/junit4/

JUnit4使用的基本知识

JUnit4在java项目中的应用(这里我的IDE是eclipse): 项目属性–>java build path–>libraries–>add library–>JUnit

  • 测试方法上必须使用@Test进行修饰
  • 测试方法必须使用public void 进行修饰,不能带任何参数
  • 新建一个源代码目录来存放我们的测试代码
  • 测试类的包应该和被测试类保持一致
  • 测试单元中的每个方法必须可以独立测试,测试间不能有任何的依赖
  • 测试类使用Test作为类名的后缀。(不是必须)
  • 测试方法使用test作为方法名的后缀。(不是必须)
Read more »