I can't believe my solution worked(inelegant C# code)


  • 0
    P

    Warning: inelegant C# code

                {
                    var negative = false;
                    var y= x.ToString();
                  var list= new List<char>();
                    foreach (var variable in y)
                    {
                        if (variable=='-')
                        {
                            negative = true;
                            continue;
                        }
                        list.Add(variable);
                    }
                    if (negative)
                    {
                        list.Add('-');
                    }
                    foreach (var variable in list)
                    {
                        Console.WriteLine(variable);
                    }
                    list.Reverse();
                   var a= list.ToArray();
                    Console.WriteLine(a);
                   var z= new string(a);
                    int pi = 0;
                    try
                    {
                        pi = Convert.ToInt32(z);
                    }
                    catch (Exception e)
                    {
                        return 0;
                    }
                    
    
                    Console.WriteLine("huehue" + pi);
                    return pi;
                   
    
           
    
                }  ```

Log in to reply
 

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