发表于: 2017-12-02 19:03:59
1 584
今日完成:
看了书中mvc在不用web.xml的情况下进行配置和测试类如何测试接口。上网看了下算法网站,用了一些时间想第一题,觉得思维不够发散。
明日计划:
听说同伴终于要找大佬检查任务了,希望明天能复盘评审。
成果:
这是那道算法题的题目,看到第一眼,英语?what?
Write a function
class Solution { public int solution(int[] A);
that, given an array A of N integers, returns the smallest positive integer (greater than 0) that does not occur in A
For example, given A = [1, 3, 6, 4, 1, 2], the function should return 5
Given A = [1, 2, 3], the function should return 4
Given A = [−1, −3], the function should return 1
Assume that
N is an integer within the range [1..100,000];
each element of array A is an integer within the range [−1,000,000..1,000,000].
Complexity
expected worst-case time complexity is O(N);
expected worst-case space complexity is O(N), beyond input storage (not counting the storage required for input arguments).
直到看到for example,given A = [1, 3, 6, 4, 1, 2], the function should return 5,Given A = [1, 2, 3], the function should return 4,Given A = [−1, −3], the function should return 1这三句就知道是什么意思了,就是写一个算法计算这三个数组,最后返回那个数,前五分钟看懂题目,想了二十分钟,实现写了五分钟,都是靠硬算找出的规律,我想到的规律就是把数组中每个数都变为n*n+A【n-1】,数组中最后一个数一直减前面的数,代码上就是
int answer=A.length*A.length+A[A.length-1]
for(int i=A.length-1;i>0;i--){
answer=answer-(i*i+A[i-1])
}
mvc的无web.xml的控制器:
@Configuration
@EnableWebMvc //启动SpringMVC
public class SpittleController{
@RequestMapping
public String spittles(){
return "view";//返回视图名
}
}
控制器和平时写的没区别,测试类中
@test
public void shouldShowPageSpittles() throws exception{
SpittleController controller =new controller();
//直接指定视图。
MockMvc mockMvc=standaloneSetup(controller).setSingleView(new InternalResourvrView("/WEB-INF/views/view.jsp")).build;
//测试接口
mockMvc.perform(get("/spittles?")).addExpect(view().name("spittles")).andExpect(model().attributeExists("spittleList")).hasItems(expectedSpittles.toArray());
}
这里只是测试类的实现,如果是实际远程反问时该如何设置视图,是打jar包通过定义一个主类来直接运行吗?
今天没打代码,主要了解一下这中构建mvc的方式,想问师兄不用web.xml来配置这种方法实用吗?如果意义不大我就不看了,虽然这是书上的。
进度:
等复盘。
评论