Ex Score complete extent mean 1 2 char op 2 0 717/719(解答错误,迭代条件写错) 按长度枚举 3 0 523/537(超时,弱智题已AC) 枚举 4 0
Experience++
each problem can be submitted infinitely with negligible punishment time some cases of the problem is hidden. each kernel function can be utilized without citing header file. notice to discriminate errors ,be them wrong solution(usually on wrong iteration condition &grammar error) or runtime exceeding .
Ex2:按长度暴力枚举
my solution
class Solution {
public :
int jiecheng ( int x, int l) {
int z= x;
for ( int i= 0 ; i< l; i++ ) {
if ( z> pow ( 10 , 4.5 ) )
return 0 ;
z= z* z;
}
return z;
}
bool search ( vector< int > & nums, int L) {
int x= 2 ;
while ( jiecheng ( x, ( L- 1 ) / 2 ) ) {
int sign= 1 ;
for ( int i= 0 ; i< ( L- 1 ) / 2 ; i++ ) {
int x_i_time= 0 ;
for ( int j= 0 ; j< nums. size ( ) ; j++ ) {
if ( nums[ j] == jiecheng ( x, i) )
x_i_time++ ;
}
if ( x_i_time< 2 ) {
x++ ; sign= 0 ;
break ;
}
}
if ( sign== 1 ) {
int x_L_time= 0 ;
for ( int j= 0 ; j< nums. size ( ) ; j++ ) {
if ( nums[ j] == jiecheng ( x, ( L- 1 ) / 2 ) )
x_L_time++ ;
}
if ( x_L_time== 0 ) {
x++ ; break ;
}
return true ;
}
}
return false ;
}
int maximumLength ( vector< int > & nums) {
int num_one= 0 ;
int ans= 1 ;
for ( int i= 0 ; i< nums. size ( ) ; i++ ) {
if ( nums[ i] == 1 ) num_one++ ;
}
if ( num_one> 0 ) {
if ( num_one% 2 == 1 ) ans= num_one;
else ans= num_one- 1 ;
}
if ( ans>= 11 ) return ans;
for ( int L= 11 ; L> 1 ; L-= 2 ) {
if ( search ( nums, L) == true )
return L> ans? L: ans;
}
return ans;
}
} ;
result
更正
36行后,删去"break;":若不行,x++后进入下一个循环判断,break就忽略了可能的取值(break是跳出当前循环)
Ex4
reading
class Solution {
public :
int minOrAfterOperations ( vector< int > & nums, int k) {
}
} ;