简历:The Google Resume: How to Prepare for a Career and Land a Job at Apple, Microsoft, Google, or any Top Tech Company
算法学习书籍:Introduction to Algorithms
编程珠玑:Programming Pearls (2nd Edition)
C++ 学习:The C++ Programming Language, 4th Edition
经典操作系统书籍,龙书:Operating System Concepts
创业:The Start-up of You: Adapt to the Future, Invest in Yourself, and Transform Your Career
Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal tox.
You should preserve the original relative order of the nodes in each of the two partitions.
For example,
Given
return
» Solve this problemGiven
1->4->3->2->5->2
and x = 3,return
1->2->2->4->3->5
.自己写的时候很多小问题,借鉴了别人的方法,逻辑设计比我简洁很多,而且也避免了判断head的情况,很值得学习,少定义了太多变量。
在改一个bug的时候有一个判断while(p->val<x&&p!=NULL) 改成了 while(p!=NULL&&p->val<x)就通过了。。这到底是为什么?内部是怎么实现的?会导致什么区别?
此题没啥太多算法,细心就行了。
&&先从左边保证它不为NULL
ReplyDelete&&是从左向右判断,所以要先判断是不是NULL。否则,可能访问一个NULL的val,会有run time error。 BTW, 我在刷LeetCode的时候经常会对照学姐你的code,你的思路总是很清晰,随我帮助很大。谢谢!
ReplyDelete