Easy to understand C++ solution. Using F(n) = (n-1)*[F(n-1)+F(n-2)]

```
public:
int findDerangement(int n) {
if(n==0||n==1)
return 0;
else {
long long int a=1,b=0,ans;
for(int i=0;i<=n;i++) {
ans = ((i-1)*(a+b))%1000000007;
b = a;
a = ans;
}
return ans;
}
}
};
```