首页 > 其他 > 详细

LF.33.number Of Nodes

时间:2018-03-27 13:12:15      阅读:211      评论:0      收藏:0      [点我收藏+]

Return the number of nodes in the linked list.

Examples

L = null, return 0
L = 1 -> null, return 1
L = 1 -> 2 -> null, return 2

 

 

 1 public class Solution {
 2   public int numberOfNodes(ListNode head) {
 3     // Write your solution here
 4     if (head == null) {
 5         return 0;
 6     }
 7     int res = 0;
 8     ListNode curr = head ;
 9     while(curr != null){
10         curr = curr.next ;
11         res++;
12     }
13     return res ;
14   }
15 }

 

LF.33.number Of Nodes

原文:https://www.cnblogs.com/davidnyc/p/8656790.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!