leetCode刷題筆記 2017 01 28

2021-07-26 11:32:10 字數 735 閱讀 4712

2. add two numbers

這其實比昨天那道相加的問題還簡單一點。。。原理一樣。

public class solution

else if (curr1 != null && curr2 == null)

else

curr = curr.next;

}listnode currn = output.next;

while (currn != null)

else

}currn = currn.next;

}return output.next;}}

328. odd even linked list

這題就是吧建立兩個鍊錶再順鍊錶兩個兩個移動,將奇數偶數分別加到這兩個鍊錶後面。

public class solution

listnode oddnode = head;

listnode evennode = head.next;

// referance for moving on

listnode curro = oddnode;

listnode curre = evennode;

while (curro.next != null && curre.next != null)

// connect two chain

curro.next = evennode;

return oddnode;}}

LeetCode刷題實戰201 數字範圍按位與

given a range m,n where 0 m n 2147483647,return the bitwise and of all numbers in this range,inclusive.給定範圍 m,n 其中 0 m n 2147483647,返回此範圍內所有數字的按位與 包含 ...

Leetcode刷題筆記

1.兩數之和給定乙個整數陣列nums 和乙個目標值target,請你在該陣列中找出和為目標值的那兩個整數,並返回他們的陣列下標。ps 你可以假設每種輸入只會對應乙個答案。但是,你不能重複利用這個陣列中同樣的元素。思路 用target減去nums中的每乙個數,並設立乙個字典來記錄對應的下標 class...

LeetCode刷題筆記

實現strstr 給定乙個 haystack 字串和乙個 needle 字串,在 haystack 字串中找出 needle 字串出現的第乙個位置 從0開始 如果不存在,則返回 1。示例 1 輸入 haystack hello needle ll 輸出 2 示例 2 輸入 haystack aaaa...