Skip to content
Discussion options

You must be logged in to vote

@LPenny-github

你好 😊


        string valueInBinary = "";

這也可以叫 valueAsBinaryString


我其實不知道為什麼它 是對的/可以產生對的結果 😅。

while 這段會蒐集 val 裡的數值,存在 valueInBinary 裡。

        while (head != null)
        {
            valueInBinary += head.val.ToString();
            head = head.next;
        }

然後呼叫 Convert.ToInt32() ( https://docs.microsoft.com/en-us/dotnet/api/system.convert.toint32?view=net-5.0#System_Convert_ToInt32_System_String_System_Int32_ ) ,讓 Convert.ToInt32() 知道 valueInBinary.ToString() 內含的「文字」是 2 進位表示法,將那些文字轉為 Int32

        return Convert.ToInt32(valueInBinary.ToString(),2);

附帶一提,因為 valueInBinary 本身就已經是 string ,所以 .ToString() 是不必要的。 😊


也有想過要設中斷點,但是不知道怎麼寫

LeetCode 應該有列出 LstNode 的定義:

/**

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by LPenny-github
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants