mirror of
				https://github.com/krahets/hello-algo.git
				synced 2025-11-04 14:18:20 +08:00 
			
		
		
		
	* feat: add Swift codes for linear_search article * feat: add Swift codes for binary_search article * feat: add Swift codes for hashing_search article
		
			
				
	
	
		
			25 lines
		
	
	
		
			531 B
		
	
	
	
		
			Swift
		
	
	
	
	
	
			
		
		
	
	
			25 lines
		
	
	
		
			531 B
		
	
	
	
		
			Swift
		
	
	
	
	
	
/**
 | 
						|
 * File: ListNode.swift
 | 
						|
 * Created Time: 2023-01-02
 | 
						|
 * Author: nuomi1 (nuomi1@qq.com)
 | 
						|
 */
 | 
						|
 | 
						|
public class ListNode {
 | 
						|
    public var val: Int // 结点值
 | 
						|
    public var next: ListNode? // 后继结点引用
 | 
						|
 | 
						|
    public init(x: Int) {
 | 
						|
        val = x
 | 
						|
    }
 | 
						|
 | 
						|
    public static func arrToLinkedList(arr: [Int]) -> ListNode? {
 | 
						|
        let dum = ListNode(x: 0)
 | 
						|
        var head: ListNode? = dum
 | 
						|
        for val in arr {
 | 
						|
            head?.next = ListNode(x: val)
 | 
						|
            head = head?.next
 | 
						|
        }
 | 
						|
        return dum.next
 | 
						|
    }
 | 
						|
}
 |