# leetcode第一天

leetcode 第一天
2017年12月24日

## 数组

#### 1.（674）Longest Continuous Increasing Subsequence

##### JAVA
class Solution {
public int findLengthOfLCIS(int[] nums) {
int tem = 1 , length = 1;
if(nums.length==0) return 0;
for (int i = 0;i<nums.length -1;i++){
if ( nums[i+1] - nums[i] > 0){
tem ++;
length = Math.max(tem,length);
}else{
tem = 1;
}
}
return length;
}
}

##### Python
class Solution(object):
def findLengthOfLCIS(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
max_len = tem_len = 1
if len(nums)==0:
return 0
for i in range(len(nums)-1):
if nums[i+1] >nums [i]:
tem_len += 1
max_len = max(tem_len,max_len)
else:
tem_len = 1
return max_len


#### 2.(283)Move Zeroes

##### JAVA
class Solution {
public void moveZeroes(int[] nums) {
int pointer = 0;
for (int i = 1; i<nums.length;i++){
if(nums[i]-nums[pointer] == nums[i]){
if(nums[i] != 0){
nums[pointer] = nums[i];
nums[i]=0;
pointer++;
}
}else pointer++;
}
}
}

##### Python
class Solution(object):
def moveZeroes(self, nums):
"""
:type nums: List[int]
:rtype: void Do not return anything, modify nums in-place instead.
"""
pointer = 0
for i in range(len(nums)):
if(nums[i]-nums[pointer] == nums[i]):
if(nums[i]!=0):
nums[pointer] = nums[i]
nums[i] = 0
pointer +=1
else:
pointer+=1


#### 3.（581）Shortest Unsorted Continuous Subarray

##### JAVA
class Solution {
public int findUnsortedSubarray(int[] nums) {
boolean isFirst = true;
int left = 0,right = 0,min = Integer.MAX_VALUE,max=Integer.MIN_VALUE;
for(int i = 0;i<nums.length-1;i++){
if(nums[i+1] < nums[i]){
if(isFirst){
left = i;
right = i+1;
isFirst = false;
}else{
right = i+1;
}
}
}
for (int i = left;i<=right;i++){
min = Math.min(min,nums[i]);
max = Math.max(max,nums[i]);
}
for(int i=0;i <= left;i++){
if(nums[i] > min){
left = i;
}
}
for(int i = nums.length-1 ; i>=right;i--){
if(nums[i]<max){
right = i;

}
}
return right==0?0:right-left+1;
}
}


02-27 6

07-31 69

04-29 28

02-21 34

06-21 142

03-01 1071

12-21 15万+

08-14 501

10-08 2026

01-25 3万+

08-27 3383

04-23 1452

09-06 4万+

02-03 1014

03-04 9098

05-28 3627

07-31 3395

09-10 3878

04-12 535

05-19 828

#### leetcode刷题阶段总结

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客