최대 1 분 소요


image

What I’ve Learned

First, Think simple. Questions are not that hard than you think.

Disclaimer

For LeetCode, I started learning about data structures on Udemy. I’ve been studying with lecture named Java Data Structures & Algorithms + LEETCODE Exercises.

DLL: Swap First and Las

Solution

Actually, this question is not a hard one. It’s simple as it seems. But, I thought too deep. I thought I need to change the Nodes literally. So, I’ve used Node temp to store the head Nodes, swap using head.next.prev… I need to think simpler.

   public void swapFirstLast(){
	    if(length < 2) return;
	    int temp = head.value;
	    head.value = tail.value;
	    tail.value = temp;
	    
	}


카테고리:

업데이트: