style: update comment format

This commit is contained in:
nuomi1
2023-01-08 20:53:24 +08:00
parent 7556558704
commit 3b52df2a8f
7 changed files with 55 additions and 54 deletions

View File

@@ -177,7 +177,7 @@ comments: true
=== "Swift"
```swift title=""
//
/* */
class Node {
var val: Int
var next: Node?
@@ -187,7 +187,7 @@ comments: true
}
}
// 函数
/* 函数 */
func function() -> Int {
// do something...
return 0
@@ -436,14 +436,14 @@ comments: true
return 0
}
// 循环 O(1)
/* 循环 O(1) */
func loop(n: Int) {
for _ in 0 ..< n {
function()
}
}
// 递归 O(n)
/* 递归 O(n) */
func recur(n: Int) {
if n == 1 {
return
@@ -604,7 +604,7 @@ $$
=== "Swift"
```swift title="space_complexity.swift"
// 常数阶
/* 常数阶 */
func constant(n: Int) {
// 常量、变量、对象占用 O(1) 空间
let a = 0
@@ -743,7 +743,7 @@ $$
=== "Swift"
```swift title="space_complexity.swift"
// 线性阶
/* 线性阶 */
func linear(n: Int) {
// 长度为 n 的数组占用 O(n) 空间
let nums = Array(repeating: 0, count: n)
@@ -834,7 +834,7 @@ $$
=== "Swift"
```swift title="space_complexity.swift"
// 线性阶(递归实现)
/* 线性阶(递归实现) */
func linearRecur(n: Int) {
print("递归 n = \(n)")
if n == 1 {
@@ -954,7 +954,7 @@ $$
=== "Swift"
```swift title="space_complexity.swift"
// 平方阶
/* 平方阶 */
func quadratic(n: Int) {
// 二维列表占用 O(n^2) 空间
let numList = Array(repeating: Array(repeating: 0, count: n), count: n)
@@ -1047,7 +1047,7 @@ $$
=== "Swift"
```swift title="space_complexity.swift"
// 平方阶(递归实现)
/* 平方阶(递归实现) */
func quadraticRecur(n: Int) -> Int {
if n <= 0 {
return 0
@@ -1154,7 +1154,7 @@ $$
=== "Swift"
```swift title="space_complexity.swift"
// 指数阶(建立满二叉树)
/* 指数阶(建立满二叉树) */
func buildTree(n: Int) -> TreeNode? {
if n == 0 {
return nil

View File

@@ -876,7 +876,7 @@ $$
=== "Swift"
```swift title="time_complexity.swift"
// 常数阶
/* 常数阶 */
func constant(n: Int) -> Int {
var count = 0
let size = 100000
@@ -990,7 +990,7 @@ $$
=== "Swift"
```swift title="time_complexity.swift"
// 线性阶
/* 线性阶 */
func linear(n: Int) -> Int {
var count = 0
for _ in 0 ..< n {
@@ -1121,7 +1121,7 @@ $$
=== "Swift"
```swift title="time_complexity.swift"
// 线性阶(遍历数组)
/* 线性阶(遍历数组) */
func arrayTraversal(nums: [Int]) -> Int {
var count = 0
// 循环次数与数组长度成正比
@@ -1267,7 +1267,7 @@ $$
=== "Swift"
```swift title="time_complexity.swift"
// 平方阶
/* 平方阶 */
func quadratic(n: Int) -> Int {
var count = 0
// 循环次数与数组长度成平方关系
@@ -1477,7 +1477,7 @@ $$
=== "Swift"
```swift title="time_complexity.swift"
// 平方阶(冒泡排序)
/* 平方阶(冒泡排序) */
func bubbleSort(nums: inout [Int]) -> Int {
var count = 0 // 计数器
// 外循环:待排序元素数量为 n-1, n-2, ..., 1
@@ -1656,7 +1656,7 @@ $$
=== "Swift"
```swift title="time_complexity.swift"
// 指数阶(循环实现)
/* 指数阶(循环实现) */
func exponential(n: Int) -> Int {
var count = 0
var base = 1
@@ -1764,7 +1764,7 @@ $$
=== "Swift"
```swift title="time_complexity.swift"
// 指数阶(递归实现)
/* 指数阶(递归实现) */
func expRecur(n: Int) -> Int {
if n == 1 {
return 1
@@ -1896,7 +1896,7 @@ $$
=== "Swift"
```swift title="time_complexity.swift"
// 对数阶(循环实现)
/* 对数阶(循环实现) */
func logarithmic(n: Int) -> Int {
var count = 0
var n = n
@@ -1999,7 +1999,7 @@ $$
=== "Swift"
```swift title="time_complexity.swift"
// 对数阶(递归实现)
/* 对数阶(递归实现) */
func logRecur(n: Int) -> Int {
if n <= 1 {
return 0
@@ -2137,7 +2137,7 @@ $$
=== "Swift"
```swift title="time_complexity.swift"
// 线性对数阶
/* 线性对数阶 */
func linearLogRecur(n: Double) -> Int {
if n <= 1 {
return 1
@@ -2288,7 +2288,7 @@ $$
=== "Swift"
```swift title="time_complexity.swift"
// 阶乘阶(递归实现)
/* 阶乘阶(递归实现) */
func factorialRecur(n: Int) -> Int {
if n == 0 {
return 1
@@ -2658,7 +2658,7 @@ $$
=== "Swift"
```swift title="worst_best_time_complexity.swift"
// 生成一个数组,元素为 { 1, 2, ..., n },顺序被打乱
/* 生成一个数组,元素为 { 1, 2, ..., n },顺序被打乱 */
func randomNumbers(n: Int) -> [Int] {
// 生成数组 nums = { 1, 2, 3, ..., n }
var nums = Array(1 ... n)
@@ -2667,7 +2667,7 @@ $$
return nums
}
// 查找数组 nums 中数字 1 所在索引
/* 查找数组 nums 中数字 1 所在索引 */
func findOne(nums: [Int]) -> Int {
for i in nums.indices {
if nums[i] == 1 {
@@ -2677,7 +2677,7 @@ $$
return -1
}
// Driver Code
/* Driver Code */
func main() {
for _ in 0 ..< 10 {
let n = 100