implement the Feiqinabo series by nonrecursive methord


  • 0
    M

    public class Solution{

    public int Fn(int n){
    	
    	 int result[] = {0,1,n};
    	
    	 if (n < 2) return n;
    	 
    	 for (int i = 2 ;i <= n ; i ++) {
    		result[2] = result[0] + result[1];
    		result[0] = result[1];
    		result[1] = result[2];
    	}		
    	return result[2];
    	
    }
    }
    

    }


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.