Swift.合并两个排序的链表

题目描述:import Foundation class For17Solution { func mergeListNode(_ head1: ListNode?,_ head2: ListNode?) -> ListNode? { if head1 == nil { return head2 } if head2 == nil { return head1 } var newHead : ...

LeetCode 2015-07-09 PM 366℃ 0条

Swift.链表中倒数第K个节点

题目描述:链表中倒数第 K 个结点。import Foundation class For15Solution { func reversedK(_ head: ListNode?,_ k: Int) -> ListNode? { guard head != nil && k != 0 else { return nil } var i = 0 var p = head var q = head ...

LeetCode 2015-07-08 PM 451℃ 0条

Swift.反转链表

题目描述:1->2->3->4,4->3->2->1import Foundation class For16Solution { func reversedListNode(_ head: ListNode?) -> ListNode? { if head == nil || head?.next == nil { return head } var pre : ListNode? var cur = head p...

LeetCode 2015-07-08 PM 472℃ 0条

Swift.调整数组顺序使奇数位于偶数前面

题目描述:调整数组顺序使奇数位于偶数前面。import Foundation class For14Solution { func ReorderOddEven(_ n: [Int]) -> [Int] { var s = n var left = 0 var right = n.count - 1 while left < right { while left < right && s[left...

LeetCode 2015-07-08 PM 439℃ 0条

Swift.在0(1)时间删除链表节点

题目描述:在 O(1) 时间内删除链表节点import Foundation class For13Solution { func deleteNode(_ head: ListNode?,_ pDeleted: ListNode?) -> ListNode? { var p = head if p == nil || pDeleted == nil { return p } if pDeleted?.next != nil { ...

LeetCode 2015-07-07 PM 410℃ 0条