学习udemy1小时 √
看一页head first java √
刷两道 leetcode √
Add Two Numbers
题目是这样的:You are given two non-empty linked lits representing two non-negative integers. The digits are stored in revere order and each of their nodes contain a single digit. Add the two numbers and return it as a linked list.
这道题根本没思路,所以直接看的视频讲解,这个youtube讲的还不错
https://www.youtube.com/watch?v=aM4Iv7eEr2o
就感觉今天看的那道medium的题还是很有用的,至少思路对我很有帮助。头一次发现Listnode可以直接用来linked list。(我以为要自己写……)
因为本身这个list已经reverse 了,所以直接相加就好。主要是把carry写好,然后在多出x位数字的情况也写好就可以了。
Ternary
Ternary 在java里面用到的地方很多,其实就是if then 这样,表现为“?:”,比如(x==3) ? y:3,意思就是,如果x等于3,那么把y设置成3。
网友评论