public class Solution { public IListAddOperators(string num, int target) { var result = new List (); Dfs(target, num, 0, 0, '+', , ref result); return result; } private void Dfs(int target, string num, long current , long prevNum, char prevOp, string s, ref List result) { if (num == ) { if(current == target){ result.Add(s); } return; } for(var i = 1 ;i <= num.Length; i++) { var str = num.Substring(0, i); if(str.Length > 1 && str[0] == '0'){ return; } long n = long.Parse(str); var left = num.Substring(i, num.Length - i); if(s == ){ Dfs(target, left, n, n,'+', str, ref result); continue; } //Console.WriteLine(str + ,+index); Dfs(target, left, current + n, n,'+', s +++str, ref result); Dfs(target, left, current - n, n,'-', s +-+str, ref result); // for '*' operator , execute reverse operation for previous operation if(prevOp == '+'){ Dfs(target, left, current - prevNum + prevNum * n, prevNum * n, prevOp, s +*+str, ref result); } else if(prevOp == '-'){ Dfs(target, left, current + prevNum - prevNum * n, prevNum * n, prevOp, s +*+str, ref result); } else{ Dfs(target, left, current * n, n, prevOp, s +*+str, ref result); } } } }