---
# System prepended metadata

title: 0422 Don't do LeetCode…Yet!

---

# 0422 Don't do LeetCode…Yet! 

lidemyMentorProgram5th week2 day4

> 目標：從覺得 Leetcode 題目很難變成看得懂又會寫！


初學者寫程式：

1. 先想解法，先不要寫程式碼
2. 把解法寫成 pseudo code
3. 把 pseudo code 翻成程式碼

---

從先用中文說明步驟，翻成英文，再轉成虛擬碼 pseudo code 範例


**請印出1 ~100**

```
令 i 為 1
如果 i > 100 ，結束
印出 i
然後讓 i = i+1
跳回第 2 行
```

翻譯成英文 

```
let i = 1
if i > 100 then exit
print i
i = i+1
jump to line 2 
```

寫成虛擬碼 

```
for ( i from 1 to 100 ) do
  print i
end for
```

**印出1 ~100 的奇數**

```
for ( i from 1 to 100 ) do
 if ( n mod 2 === 1 ) then   (對 2 取餘數強等於 1)
   print i
 end if
end for
```

**經典題 fizz buzz**

```
for ( i from 1 to n ) do
   if ( i % 15 ===0 ) print ‘FizzBuzz’
   else if ( i % 3 === 0) print ‘Fizz’
   else if ( i % 5 === 0) print ‘Buzz’
end for
```

**找最小的牌 (從陣列理找最小值)**

```
let 最小的牌 = 第一張牌
for ( i from 1 to n ) do
  翻開第 i 張牌
  if ( 第 i 張牌比最小牌的還小) do
     最小的牌 = 第 i 張牌
  end if
end for
```

```
let min = arr [0]
for ( i from 0 to n-1 )do
  if ( arr [i] < min ) do
     min = arr [i] 
  end if
end for
```
