# 2019互联网笔试题编程答案部分

def handle():
n = input()
n = int(n)
nums = [int(num) for num in input().split(" ")]
if n < 3:
return n
_pre = [1] * n
_next = [1] * n
for i in range(1, n):
if nums[i] > nums[i-1]:
_pre[i] = _pre[i-1] + 1
for i in range(n-2, -1, -1):
if nums[i+1] > nums[i]:
_next[i] = _next[i+1] + 1
ans = 1
for i in range(1, n-1):
ans = max(ans, _pre[i], _next[i])
if nums[i+1] - nums[i-1] >= 2:
ans = max(ans, _pre[i-1] + _next[i+1] + 1)
return ans

print(handle())

3

3

1 2 3 4 5 6 7 8 9

static int[] spiralOrder(int[][] arr) {
int [] res = new int[arr.length*arr[0].length];
int count = 0;
if(arr == null || arr.length == 0)
return null;
int startX = 0, startY = 0;
int endX = arr[0].length - startX - 1, endY = arr.length - startY - 1;
while(startX * 2 < arr[0].length && startY * 2 < arr.length) {
for(int i = startX; i <= endX; ++i) {
res[count++] = arr[startY][i];
}
if(startY < endY) {
for(int i = startY + 1; i <=endY; ++i) {
res[count++] = arr[i][endX];
}
}
if(startX < endX && startY < endY) {
for(int i = endX - 1; i >= startX; --i) {
res[count++] = arr[endY][i];
}
}
if(endY > (startY + 1) && startX < endX) {
for(int i = endY - 1; i > startY; --i) {
res[count++] = arr[i][startX];
}
}
startX++;
startY++;
endX--;
endY--;
}
return res;
}

Java replace 源码

    public String replace(char oldChar, char newChar) {
if (oldChar != newChar)
{
int len = value.length;//value就是一个数组,这里得到string字符串的长度
int i = -1;
char[] val = value; /* avoid getfield opcode */

while (++i < len)      //先确保字符串中有旧的字符
{
if (val[i] == oldChar)
{break;}
}

if (i < len)
{
char buf[] = new char[len];
for (int j = 0; j < i; j++)
{
buf[j] = val[j];
}
while (i < len) {
char c = val[i];
buf[i] = (c == oldChar) ? newChar : c;
i++;
}
return new String(buf, true);
}
}
return this;
}

import java.util.Scanner;

public class Main{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int result=getResult(n-1,n)+getResult(n-2,n)+getResult(n-3,n);
System.out.println(result);
}
public static int getResult(int n,int m)
{
if(n==0) return 1;
if(n==1 || n==2) return 1;
if(n==m-1)
{
return getResult(n-2,n)+getResult(n-3,n);
}
else
{
return getResult(n-1,n)+getResult(n-2,n)+getResult(n-3,n);
}
}
}

1-n栋房子标号相差1 为相邻，k栋房子已经有住户，你需要所住的房子两边都有住户，求最小的可能符合的和最大符合房子数

###---最小为0 #-#-# -最大为2

import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int t = in.nextInt();
for(int i = 0; i < t; i++) {
int min = 0, max;
int n = in.nextInt();
int k = in.nextInt();
if(n % 2 == 0) {
if(k > n / 2) {
max = n - k;
} else {
max = k - 1;
}
} else {
if(k > n / 2 + 1) {
max = n - k;
} else {
max = k - 1;
}
}
if(n < 3) {
max = 0;
}
if(max < 0) {
max = 0;
}
System.out.println(min + " " + max);
}
}
}

1，给定字符串输出字符串中不重复的最长子串的长度 例如：输入‘acddw’ 输出3  输入‘bbbb’ 输出 1

def solution(one_str):
res_list=[]
length=len(one_str)
for i in range(length):
tmp=one_str[i]
for j in range(i+1, length):
if one_str[j] not in tmp:
tmp+=one_str[j]
else:
break
res_list.append(tmp)
res_list.sort(lambda x,y:cmp(len(x),len(y)))
return res_list[-1]
ss=solution(s)
print len(ss)