For this problem, you can guess and check.

If we have 7 bags of 9 apples, it totals 63 apples.

If we have 7 bags of 5 apples, it toals 35 apples.

Each time we replace a bag of 9 apples with 5, it deducts 4 apples from the total.

63-51=12 apple difference from 7 bags of 9 apples from the actual number of apples

12/4=3 bags of red apples

7-3=4 bags of green apples

__Therefore, there are 4 bags of green apples and 3 bags of red apples.__

(doing it backwards to prove that it's correct)

4x9=36

3x5=15

36+15=51.