【文件属性】:
文件名称:leetcode2-Leetcode-Swift-Solution:如何用Swift破解Leetcode问题!
文件大小:466KB
文件格式:ZIP
更新时间:2021-06-29 21:26:59
系统开源
leetcode
2
Leetcode-Swift-解决方案
如何用
Swift
破解Leetcode问题!
在讨论任何特定的
Leet
代码问题之前,让我们先了解一些您需要了解的非常有用的技巧和技巧。
有了这些提示,您将能够处理大多数简单的问题而不会出现太多问题。
同时,如果您不熟悉算法大O的概念,请事先查看其他地方。
还有一件事我想提一下,每次在你编码你的解决方案甚至
AC
之后,确保你确切地知道你的算法时间和空间复杂度。
看看它是最好的还是有其他方法可以使它更好。
换句话说,无论您的解决方案是
O(n^2)
都可以优化为
O(NlogN)
甚至
O(n)。
这是一些备忘单
bigO
的图片
备忘单的图片
使用dictionary
or
set而不是
2
for
循环。
给定一个整数数组,返回两个数字的索引,使它们相加为特定目标。
您可以假设每个输入都只有一个解决方案,并且您不能两次使用相同的元素。
原始方法
for
i
in
0
..<
nums.
count
{
for
j
in
i
+
1
..<
nums.
coun
{
if
(nums[j]
==
target
-
nu
【文件预览】:
Leetcode-Swift-Solution-master
----README.md(13KB)
----LinkedList()
--------206- Reverse linked list.swift(1002B)
--------237- Delete Node in a Linked List.swift(321B)
--------141- Linked List Cycle.swift(563B)
--------160- Intersection of two Linked list.swift(857B)
----LICENSE(1KB)
----Common DS Operations.png(422KB)
----Tree()
--------543. Diameter of Binary Tree.swift(478B)
--------889-Construct Binary Tree from Preorder and Postorder Traversal.swift(1KB)
--------257. Binary Tree Paths.swift(638B)
--------572. Subtree of Another Tree.swift(820B)
--------617- Merge Two Binary Trees.swift(531B)
--------230. Kth Smallest Element in a BST.swift(771B)
--------404. Sum of Left Leaves.swift(502B)
--------94-Binary Tree Inorder Traversal.swift(1KB)
----BigOComplexityChart.png(60KB)