2019년 5월 31일 금요일

[Grammar in Use] Unit 26

Can, could and (be) able to

We use can to say that something is possible or allowed, 
우리는 가능한 것 또는 허락 또는
or that somebody has the ability to do something.
누군가가 어떤것을 할 수 있는 능력을 가진것에 대하여 말할때 사용.
We use can + infinitive (can do / can see etc.)

예문) 해석참고용

  • We can see the lake from our hotel.
    우리호텔에서 그 호수를 볼 수 있다.
  • I don't have a pen. You can use mine.
    나는 팬이 없어. 내 것을 써.
  • Can you speak any foreign languages?
    다른 외국어를 할 줄 아니?
  • I can come and see you tomorrow if you like.
    나는 니가 좋다면 내일 보러올수 있다. 
  • The word dream can be a noun or a verb.
    꿈이란 단어는 명사와 동사가 될 수 있다.

The negative is can't (= cannot)
예문) 해석참고용

  • I'm afraid I can't come to the party on Friday.
    나는 금요일날 그 파티에 오지 못할까 걱정되.


You can say that somebody is able to do something, but can is more usual.
당신은 is able to do 를 사용할 수 있지만 can이 더 일반적이다.

예문) 해석참고용

  • We are able to see the lake from our hotel.
    우리호텔에서 그 호수를 볼 수 있다.

But can has only two forms. can (present) and could (past).
그러나 can은 present 그리고 could (past) 만 가지고 있다.
So sometimes it is necessary to use (be) able to.
그래서 가끔은 be able to형식을 사용할 필요가 있다.

Compare
예문) 해석참고용

  • I can't sleep.
    나는 잠잘 수 없다.
  • I haven't been able to sleep recently.
    나는 최근에 참을 잘 수가 없었다.
  • Tom can come tomorrow.
    톰은 내일 올 수 있다.
  • Tom might be able to come tomorrow.
    톰은 아마 내일 올 것 같다.
  • Maria can speak French, Spanish and English.
    마리아는 프랑스, 스페인 그리고 영어를 말할 수 있다.
  • Applicants for the job must be able to speak two foreign languages.
    그 직장을 지원하는건 2개의 언어를 할 줄 알아야 한다.


Could
Sometimes could is the past of can. We use could especially with.
때론, could는 can의 과거형이다. 우리는 특히 다음의 경우에 사용한다.
see / hear / smell / taste / feel / remember / understand

예문) 해석참고용

  • We had a lovely room in the hotel. We could see the lake.
    우리는 그 호텔에서 사랑스러운 방을 가졌다. 우리는 그 호수를 볼 수 있었다.
  • As soon as I walked into the room, I could smell gas.
    그 방에 걸어들어가자 마자, 나는 가스냄새를 맏을 수 있었다.
  • I was sitting at the back of the theatre and couldn't hear very well.
    나는 영화관의 뒷좌석에 앉아서 잘 듣지 못했다.


We also use could to say that 
우리는 또한 누군가가 일반적으로 할수 있던 것에 대한것이나, 
somebody had the general ability or permission to do something.
어떤것을 하는것에 허락을 구할때 사용합니다.

예문) 해석참고용

  • My grandfather could speak five languages.
    내 할아버지는 5개국어를 할 줄 알았다.
  • We were totally free. We could do what we wanted. (= we were allowed to do)
    우리는 아주 자유로웠다. 우리는 우리가 원하는 것들을 할 수 있었다.


Could and was able to We use could for a general ability. 
could와 was able to는 보편적 능력에 대하여 사용할 수 있다.
But if you want to say that somebody did something in a specific situation, 
그러나 만약 누군가 특정상황에서 했던 일에 대하여는 
use was / were able to or managed to (not could)
was / were able to 또는 managed to를 사용하자.

예문) 해석참고용

  • The fire spread through the building very quickly,
    but fortunately everybody was able to escape / managed to escape.
    (not could escape)
    그 불이 그 빌딩을 지나 매우 빠르게 번지고 있었지만 운이 좋게도 모두가 탈출 할 수 있었다.
  • We didn't know where David was,
    but we managed to find / were able to find him in the end. (not could find)
    우리는 다비드가 어디에 있었는지 몰랐지만 결국 그를 찾을 수 있었다.

Compare
예문) 해석참고용

  • Jack was an excellent tennis player when he was younger. He could beat anybody.
    잭은 그가 어렸을때 훌륭한 테니스 선수였다. 그는 모두 이길 수 있었다.
    (= he had the general ability to beat anybody)
  • Jack and Andy played a match yesterday.
    Andy played well, but jack managed to beat him.
    (= he managed to beat him this time)
    잭과 앤디는 어제 경기를 했다. 앤디는 잘했지만 잭이 그를 이겼다.


The negative couldn't (could not) is possible in all situations.
couldn't 는 모든 상황에서 가능하다.
예문) 해석참고용

  • My grandfather couldn't swim.
    내 할아버지는 수영을 못했다.
  • We looked for David everywhere, but we couldn't find him.
    우리는 모든곳에서 다비드를 찾았지만, 그를 찾을 수 없었다.
  • Andy played well, but he couldn't beat jack.
    앤디는 잘 했지만 그는 잭을 이길 수 없었다.


Read more ...

2019년 5월 30일 목요일

[Grammar in Use] Unit 25

When I do / When I've done
When and if



I'll phone you when I get home's is a sentence with two parts
the main part : I'll phone you.
the when-part: when I get home.


The time in the sentence is future (tomorrow), 
이 문장의 시간은 미래다. (내일)
but we use a present tense (I get) in the when-part of the sentence.
하지만 when-part에서 present tense를 사용했다.
We do not use will in the when-part of the sentence.
우리는 when-part에서는 will를 사용하지 않는다.

예문) 해석참고용

  • We'll go out when it stops raining. (not when it will stop)
    우리는 나갈거야 비가 그치면.
  • When you are in London again, come and see us. (not When you will be)
    너가 런던에 다시 오면, 보러와.
  • (said to a child) What do you want to be when you grow up? (not will grow)
    (아이에게) 너가 크면 무엇이 되고싶어?


The same thing happens after while /before / after / as soon as / until or till.
while, before, after, as soon as, until도 마찬가지다.
예문) 해석참고용

  • What are you going to do while I'm away? (not while I will be)
    내가 떠나면 뭐 할거야?
  • I'll probably go back home on Sunday. Before I go, I'd like to visit the museum.
    나는 아마 일요일에 집에 돌아갈거야. 가기전에 그 박물관에 방문하는게 좋겠어.
  • Wait here until (or till) I come back.
    내가 돌아올때까지 여기서 기다려.


You can also use the present perfect (have done) after when /after / until / as soon as.
또한 다음에서 present perfect도 사용가능하다.
예문) 해석참고용

  • Can I borrow that book when you've finished with it?
    니가 다 보면 나에게 그 책을 빌려줄 수 있니?
  • Don't say anything while lan is here. Wait until he has gone.
    란이 여기 있는 동안 아무말도 하지마. 그가 떠날때까지 기다려.


If you use the present perfect, one thing must be complete before the other.
만약 present perfect를 사용한다면 다른걸 완료시켜야 한다.
(so the two things do not happen together)
(그래서 그 두개는 함께 일어나지 않는다.)
예문) 해석참고용

  • When I've phoned Kate, we can have dinner.
    내가 케이트에게 전화하면, 우리는 밥을 먹을 수 있다.
    (= First I'll phone Kate and after that we can have dinner.)
    (= 먼저 나는 전화를 하고 나서 우리는 밥을 먹을 수 있다.)

Do not use the present perfect if the two things happen together.
2가지 일이 동시에 일어난다면 present perfect를 사용하지 말아라.
예문) 해석참고용

  • When I phone Kate, I'll ask her about the party. ( not When I've phoned)
    내가 케이트에게 전화하면, 나는 그 파티에 대하여 물어볼거야.


It is often possible to use either the present simple or the present perfect.
보통 present simple과 present perfect둘다 가능하다.
예문) 해석참고용

  • I'll come as soon as I finish.
    I'll come as soon as I've finished.
    나는 가능한 빨리 끝내고 올거야.
  • You'll feel better after you have something to eat.
    You'll feel better after you've had something to eat.
    너는 뭘 먹고나면 기분이 좋아질거야.

After if, we normally use the present simple (if I do / if I see etc.) for the future.
미래에 대하여 if이후는 보통 present simple을 사용한다.
예문) 해석참고용

  • It's raining hard. We'll get wet if we go out. (not if we will go)
    비가 강하게 오는중이라 밖에 나가면 젖을거야.
  • I'll be angry if it happens again. (not if it will happen)
    이런 일이 다시 발생하면, 화날거야.
  • Hurry up! if we don't hurry, we'll be late.
    서둘러! 서두르지 않으면 늦을거야.


When and if

We use when for things which are sure to happen.
어떤일이 확실히 일어날것에 대하여 when을 사용.
예문) 해석참고용

  • I'm going out later. (for sure) When I go out, I'll get some bread.
    나는 다음에 나갈거야. 내가 나가면 빵을 몇개 얻을거야.


We use if (not when) for things that will possibly happen.
우리는 if를 사용하면 아마도 일어날 것에 대하여 사용.
예문) 해석참고용

  • I might go out later. (it's possible) If I go out, I'll get some bread.
    나는 다음에 나갈거야. 내가 나가면 빵을 몇개 얻을거야.
  • If it is raining this evening, I won't go out. (not When it is raining)
    만약 이번 저녁에 비가 오면, 나는 나가지 않을거야.
  • Don't worry if I'm late tonight. (not when I'm late)
    나가 오늘밤 늦어도 걱정마.
  • If they don't come soon, I'm not going to wait. (not When they don't come)
    만약 그들이 곧 도착하지 않으면, 나는 기다리지 않을거야.

Read more ...

2019년 5월 29일 수요일

[leetcode] 118. Pascal's Triangle

원문)
Given a non-negative integer numRows, generate the first numRows of Pascal's triangle.

번역)
양수 숫자열이 주어졌을때, 파스칼 삼각형을 처음 열부터 만들어라.


예제)



In Pascal's triangle, each number is the sum of the two numbers directly above it.
Example:
Input: 5
Output:
[
     [1],
    [1,1],
   [1,2,1],
  [1,3,3,1],
 [1,4,6,4,1]
]

문제접근)

우선 첫번째는 넣어두고
그 다음부터는 이전 배열저장된것을 가져와서 각각 더해주고 넣어준다.
그리고 양끝에 1을 넣어준다.


코드)



 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
class Solution:
    def generate(self, numRows: int) -> List[List[int]]:
        answer = []
        
        for i in range(numRows):
            if i == 0:
                answer.append([1])
            else:
                tmp = [1]
                prev = answer[i - 1]
                l = len(prev)
                if l > 1:
                    for i in range(1, l):
                        tmp.append(prev[i-1] + prev[i])
                tmp.append(1)
                answer.append(tmp)
        return answer


Read more ...

[leetcode] 54. Spiral Matrix

원문)
Given a matrix of m x n elements (m rows, n columns),
return all elements of the matrix in spiral order.

번역)
행렬(행 M, 열 N)주어졌을때,
나선의 모든 요소들을 반환하라.


예제)


Example 1:
Input:
[
 [ 1, 2, 3 ],
 [ 4, 5, 6 ],
 [ 7, 8, 9 ]
]
Output: [1,2,3,6,9,8,7,4,5]
Example 2:
Input:
[
  [1, 2, 3, 4],
  [5, 6, 7, 8],
  [9,10,11,12]
]
Output: [1,2,3,4,8,12,11,10,9,5,6,7]


문제접근)

총 4개의 방향을 잡고 각 방향 별로 쪼개서 각 기능을 하도록 구현하였다.
반영 -> 체크 -> 움직임 으로 순서를 잡고 했다.


코드)



 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
class Solution:
    def spiralOrder(self, matrix: List[List[int]]) -> List[int]:
        answer = []
        
        m = len(matrix)
        if m == 0:
            return []
        n = len(matrix[0])
        
        left = 0
        bottom = m - 1
        right = n - 1
        top = 1
        
        row = 0
        y = 0
        col = 0
        x = 1
        state = 0
        
        while len(answer) < m * n:
            # add
            answer.append(matrix[row][col])
            
            # check
            if state == 0:
                # check
                if col == right:
                    right -= 1
                    state = 1
                    # dir
                    x = 0
                    y = 1
            elif state == 1:
                # check
                if row == bottom:
                    bottom -= 1
                    state = 2
                    # dir
                    x = -1
                    y = 0
            elif state == 2:
                # check
                if col == left:
                    left += 1
                    state = 3
                    # dir
                    x = 0
                    y = -1
            else:
                # check
                if row == top:
                    top += 1
                    state = 0
                    # dir
                    x = 1
                    y = 0
                    
            # move
            row += y
            col += x
        
        return answer


Read more ...

[leetcode] 498. Diagonal Traverse

원문)
Given a matrix of M x N elements (M rows, N columns),
return all elements of the matrix in diagonal order as shown in the below image.

번역)
행렬(행 M, 열 N)주어졌을때,
다음 그림에서 처럼 모든 요소들을 반환하라.


예제)


Example 1:
Input:
[
 [ 1, 2, 3 ],
 [ 4, 5, 6 ],
 [ 7, 8, 9 ]
]

Output:  [1,2,4,7,5,3,6,8,9]

Explanation:

Note:
The total number of elements of the given matrix will not exceed 10,000.

문제접근)

우선 쪼개서 생각해 보려고한다.

(row, col)으로 자리를 변환시켜 보면 다음과 같다.

r을 변경해보자.

변경해서 앞자리 수만 확인해보면
"00" "01" "02" "12" "22"
col 증가하다가 다 지나가면 row을 증가하는 규칙성을 확인할 수 있다.



1개는 하나이니까 2개 이상부터 보면
"01 10" "02 11 20"
이 내용도 확인해보면 row는 증가 col는 감소하는 것을 알 수 있다.
주의사항은 r인경우는 실제값은 reverse해야한다.

해당 2가지 규칙을 각각 구별하여 구분하면 구현할 수 있다.


4 X 4를 한번 보자.



해당 내용도 위의 규칙이 적용되는것을 확인하였다.



코드)


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
class Solution:
    def findDiagonalOrder(self, matrix: List[List[int]]) -> List[int]:
        m = len(matrix)
        if m == 0:
            return []
        n = len(matrix[0])
        
        ans = []
        row = 0
        col = 0
        order = 1
        
        while True:
            order *= -1
            ans += self.traverse(col, row, matrix)[::order]
            if col < n - 1:
                col += 1
            elif row < m - 1:
                row += 1
            else:
                break
        return ans
    
    def traverse(self, col, row, matrix) -> List[int]:
        ret = []

        max_m = len(matrix) - 1
        max_n = len(matrix[0]) - 1

        while col >=0 and row <= max_m:
            ret.append(matrix[row][col])
            col -= 1
            row += 1
        return ret

Read more ...

[Grammar in Use] Unit 24

Will be doing and will have done

Study this example situation

These people are standing in a queue to get into the cinema.
사람들은 영화관으로 들어가려고 줄을 서있다. 

Half an hour from now, the cinema will be full.
지금부터 30분에 극장은 꽉 찰것이다.
Everyone will be watching the film.
모두가 그 영화를 볼것이다.

Three hours from now, the cinema will be empty.
지금부터 3시간에 그 영화관은 빌것이다.
The film will have finished.
그 영화는 끝나있을것이다.
Everyone will have gone home.
모두가 집으로 돌아갈것이다.

I will be doing something (future continuous) = I will be in the middle of doing it.
나는 무언가를 하는중일것이다. = 나는 그 일을 하는 중간에 있다.

예문) 해석참고용
  • This time next week I'll be on holiday. I'll be lying on the beach or swimming in the sea.
    다음주 이시간에 휴가를 가있을 것이다. 바다에 수영을 하거나 해변에 누워있을 것이다.
  • You have no chance of getting the job. You'll be wasting your time if you apply for it.
    너는 그 직장을 구할 기회가 없어. 만약 그걸 지원한다면 시간낭비할거다.

Compare will be (do)ing and will (do)
예문) 해석참고용
  • Don't phone between 7 and 8. We'll be having dinner.
    7~8시에는 전화하지 말아줘. 우리는 저녁먹고있을거야.
  • Let's wait for Liz to arrive and then we'll have dinner.
    리즈가 도착할때까지 기다리자. 그 담에 저녁을 먹을거야.

Compare will be -ing with other continuous forms.
예문) 해석참고용
At 10 o'clock yesterday, Sally was in her office. She was working. (past)
어제 10시에 샐리는 그녀의 사무실에 있었다. 그녀는 일하는 중이였다.
It's 10 o'clock now. She is in her office. She is working. (present)
지금은 10시다. 그녀는 그녀의 사무실에 있다. 그녀는 일하는 중이다.
At 10 o'clock tomorrow, she will be in her office. She will be working.
내일 10시에는 그녀는 그녀의 사무실에 있을것이다. 그녀는 일하는 중일 것이다.

We also use will be -ing to talk about complete actions in the future.
우리는 미래의 완료된 행위에 대하여도 will be -ing를 사용한다.
예문) 해석참고용
  • The government will be making a statement about the crisis later today.
    정부는 오늘 이후에 그 위기 성명에 대하여 발표를 할 것이다.
  • Will you be going away this summer?
    이번 여름에 떠나 있을거야?
  • Later in the programme, I'll be talking to the Minister of Education ...
    그 프로그램 이후에, 나는 교육부장관과 말할 것이다.
  • Our best player is injured and won't be playing in the game on Saturday.
    우리 최고의 선수가 부상당했고 토요일날 그 게임을 할 수 없을 것이다.
In these examples will be -ing is similar to (be) going to ...

We use will have (done) (future perfect) to say that 
something will already be complete before a time in the future.
우리는 미래의 한 시간 전에 이미 완료된 것에 대하여 말할때 will have pp를 사용.

예문) 해석참고용
  • Sally always leaves for work at 8.30 in the morning.
    샐리는 항상 아침 8.30분에 일하러 떠난다.
    She won't be at home at 9 o'clock - she'll have gone to work.
    그녀는 9시에 집에 없을것이다. - 그녀는 이미 일하러 갔다.
  • We're late. The film will already have started by the time we get to the cinema.
    우리는 늦었다. 그 영화는 우리가 영화관에 도착할 시간에는 이미 시작했을 것이다.

Compare will have (done) with other perfect forms.

예문) 해석참고용
  • Ted and Army have been married for 24 years. (present perfect)
    태드와 아미는 결혼한지 24년이 되었다.
  • Next year they will have been married for 25 years.
    내년에 그들은 결혼한지 25년이 될 것이다.
  • When their son was born, they had been married for three years. (past perfect)
    그들의 자식이 태어났을때, 그들은 결혼한지 3년이 되었었다.

Read more ...

2019년 5월 28일 화요일

[Grammar in Use] Unit 23

I will and I'm going to


Future actions
Study the difference between will and (be) going to




Compare

예문) 해석참고용

  • Gary phoned while you were out. OK. I'll call him back.
    개리가 당신이 나가있는동안 전화했었다. 알았어. 그에게 다시 전화할게.
  • Gary phoned while you were out. Yes, I know. I'm going to call him back.
    개리는 당신이 나가있는동안 전화했었다. 응 알고있어. 그에게 다시 전화할거야.
  • Anna is in hospital. Oh really? I didn't know. I'll go and visit her.
    안나는 병원에 있어. 아 정말? 몰랐어. 문병가야겠네.
  • Anna is in hospital. Yes, I know. I'm going to visit her this evening.
    안나는 병원에 있어. 응 알고있어. 오늘 저녁에 문병갈거야.


Future happening and situations (predicting the future)

We use both "will" and "going to" to predict future happenings and situations.
우리는 will과 going to를 미래의 상황에 대하여 예상할때 사용한다.

예문) 해석참고용

  • I think the weather will be nice later.
    I think the weather is going to be nice later.
    내 생각에는 날씨가 좋아질거야.
  • Those shoes are well-made. They'll last a long time.
    Those shoes are well-made. They're going to last a long time.
    그 신발은 잘만들었다. 그건 오래 갈거야.


When we say something is going to happen, we know this from the situation now.
우리가 무언가 일어날 것 같아 라고 말할때는, 지금의 상항에서부터 온것이다.
우리가 예측한 일이 현재의 상황 으로부터 일어날 것을 이야기 할때 사용한다.
What is happening now shows that something is going to happen in the future.
현재 어떤일이 벌어진것에서 미래에 일어날 일이 무엇인지 알 수 있다.

예문) 해석참고용

  • Loot at those black clouds. It's going to rain. (not it will rain)
    저기에 먹구름을 봐. 비가 올거야.
    (We can see that it is going to rain from the clouds that are in the sky now.)
    (우리는 지금 하늘에 있는 그 구름들로 부터 비가 올것이라고 볼 수 있다.)
  • I feel terrible. I think I'm going to be sick. (not I think I'll be sick)
    나는 기분이 최악이야. 곧 아플거같아.
    (I think I'm going to be sick because I feel terrible now.)
    (나는 아플것 같아. 왜냐면 기분이 지금 최악이거든)


Do not use will in this type of situation.
해당사항은 will을 사용하지 않는다.

Read more ...

2019년 5월 27일 월요일

[Grammar in Use] Unit 22

Will / Shall 2


We do not use will to say what somebody has already arranged or decided to do.
누군가가 이미 결정하거나 예정된 것에 대하여는 will 을 사용하지 않는다.

예문) 해석참고용

  • Diane is working next week. (not Diane will work)
    다이앤은 다음주에 일한다.
  • Are you going to watch anything on TV this evening? (not Will you watch)
    오늘저녁에 TV를 볼거야?


But often, when we talk about the future,
그러나 자주, 우리는 미래에 대하여 이야기를 할때,

we are not talking about what somebody has decided to do.
누군가가 결심한 것에 대한 이야기는 하지 않는다.



She'll pass does not mean she has decided to pass.
She'll pass는 그녀가 pass를 결심한게 아니다.

Joe is saying what he knows or believes will happen.
조는 단지 그가 아는 것이나 그럴것이라 믿고 말하는 중이다.


He is predicting the future.
그는 그 미래를 예측한거다.
When we predict a future happening or situation, we use will/won't.
미래상황에 대한 예측을 할때 우리는  will/won't를 사용.


예문) 해석참고용

  • They've been away a long time.
    그들은 예전에 떠났다.
    When they return, they'll find a lot of changes here.
    그들이 돌아왔을때 이곳에 많은 변화가 있을 것이다.
  • Where will you be this time next year? I'll be in Japan.
    내년 이맘쯤 너는 어디에 있을거 같아? 나는 일본에 있을거야.
  • That plate is hot. If you touch it, you'll burn yourself.
    그 접시는 뜨거워. 만약 만지면, 화상입을거야.
  • Tom won't pass the exam. He hasn't studied hard enough.
    톰은 이 시험을 통과하지 못할거야. 그는 충분히 열심히 하지 않았다.
  • Anna looks completely different now. You won't recognize her.
    안나는 지금 완벽히 달라보인다. 너는 그녀를 알아채지 못할거야.
  • When will you get your exam results?
    언제 시험결과가 나와?


We often use will ('ll) with
Probably

  • I'll probably be home late tonight.
    나는 아마 집에 늦을거야.

(I'm) sure

  • Don't worry about the exam. I'm sure you'll pass.
    시험걱정하지마. 나는 너가 패스할거라 확신해.

(I) think

  • Do you think Sarah will like the present we bought her?
    너는 우리가 그녀를 위해 산 선물을 좋아해 줄것이라 생각해?

(I) don't think

  • I don't think the exam will be very difficult.
    나는 그 시험이 아주 어렵지 않을거라 생각해.

I wonder

  • I wonder what will happen.
    나는 무슨일이 일어날지 궁금하다.


After I hope, we generally use the present. (will is also possible)
I hope다음에는 보통 present형식이 온다.


예문) 해석참고용

  • I hope Kate passes the exam. (or I hope Kate will pass ...)
    나는 케이트가 그 시험을 통과할거라 희망한다.
  • I hope it doesn't rain tomorrow.
    나는 내일 비가 오지 않기를 바래.

Generally we use will to talk about the future,
미래를 이야기할때 보통 will을 사용하지만

but sometimes we use will to talk about now.
가끔은 현재를 말할때도 사용한다.


  • Don't phone Ann now. She'll be busy. (= she'll be busy now)
    안에게 지금 연락하지마. 그녀는 바쁠거야.

I shall ... / we shall ...

Normally we use shall only with I and we.
오직 I 와 we하고 같이 사용한다.


예문) 해석참고용

  • I shall be late this evening. (or I'll be)
    오늘저녁에 늦을거야.
  • We shall probably go to France in June. (or We will probably go)
    우리는 아마도 6월에 프랑스를 갈거야.

In spoken English we normally use I'll and we'll
영어에서 will을 더 많이 사용한다.

  • We'll probably go to France.
    우리는 아마 프랑스로 갈거야.

The negative of shall is shall not or shan't

  • I shan't be here tomorrow. (or I won't be)
    내일은 여기에 없을거야.

Don't use shall with he/she/it/you/they.

  • She will be very angry. (not She shall be)
    그녀는 화날것이다.


Read more ...

2019년 5월 26일 일요일

[Grammar in Use] Unit 21

Will / Shall 1

We use I'll (= I will) when we've just decided to do something.
우리가 어떤 일을 할것을 막 정했을때, I'll을 사용.

When we say I'll do something, we announce our decision.
I'll do something은 우리의 결정을 알릴때 사용한다.


예문) 해석참고용

  • Oh, I've left the door open. I'll go and shut it.
    아, 문을 열어두고 나왔어, 가서 닫아야 겠어.
  • What would you like to drink? I'll have an orange juice, please.
    뭐 마실래? 저는 오랜지 쥬스를 먹을래요.
  • Did you phone Lucy? Oh, no, I forgot. I'll phone her now.
    루시에게 전화했어? 아, 아니, 잊어버렸어. 지금 그녀에게 전화할거야.

You can't use the present simple (I do / I go etc) in these sentences.
다음 문장에서는 present simple을 사용할 수 없다.

예문) 해석참고용

  • I'll go and shut the door. (not I go and shut)
    나는 문을 닫아야 겠어.

We often use I think I'll ... and I don't think I'll ...
I think I'll ... and I don't think I'll ... 을 자주 사용한다.

예문) 해석참고용

  • I feel a bit hungry. I think I'll have something to eat.
    나는 조금 허기져. 내 생각은 뭐좀 먹어야 겠어.
  • I don't think I'll go out tonight. I'm too tired.
    내 생각엔 오늘밤은 나갈것 같지 않아. 너무 지쳤어.

In spoken English the negative of will is usually won't (= will not)
부정문을 말할때는 보통 won't 를 사용.


예문) 해석참고용

  • I can see you're busy, so I won't stay long.
    너가 바빠보여서, 오래 머무를 수 없어.
Do not use will to talk about what you decided before.
전에 결정한 것에 대하여 말할때는 will을 사용하지 않는다.

예문) 해석참고용
  • I'm going on holiday next Saturday. (not I'll go)
    다음주 토요일에 휴가를 갈거야.
  • Are you working tomorrow? (not Will you work)
    내일 일 갈거야?
We often use will in these situations.
다음 상황에서 자주 사용.

Offering to do something.
무언가를 제공할때.
  • That bag looks heavy. I'll help you with it. (not I help)
    저 가방은 무거워보여. 도와줄게.
Agreeing to do something.
무언가를 동의할때.
  • A: Can you give Tim this book?
    A: 팀에게 이 책을 줄 수 있니?
  • B: Sure, I'll give it to him when I see him this afternoon.
    B: 물론, 오늘 오후에 그를 볼때 줄거야.

Promising to do something.
무언가를 약속할때.
  • Thanks for lending me the money. I'll pay you back on Friday.
    나에게 돈을 빌려줘서 고마워. 금요일까지 갚을게.
  • I won't tell anyone what happened. I promise.
    나는 어느 누구에게 무슨일이 일어났지에 대하여 말 안할거야. 약속해.
Asking somebody to do something (Will you ... ?)
누군가에게 무언가를 요청할때.
  • Will you please turn the music down? I'm trying to concentrate.
    음악을 꺼 주실 수 있나요? 나는 집중하고 있어요.

You can use won't to say that somebody refuses to do something.
won't는 누군가가 무엇 하는것을 거절하였을때 사용.
  • I've tried to give her advice, but she won't listen.
    나는 그녀에게 조언을 주려고 시도했지만 그녀는 듣지 않았어.
  • The car won't start. (= the car refuses to start)
    그 차는 움직이지 않아.

Shall I ... ? Shall we ...?

Shall is used mostly in the questions shall I ... ? / Shall we ...?
Shall은 대부분 의무문으로 사용.

We use shall I ... ? / shall we ... ?
to ask somebody's opinion (especially in offers or suggestions)
누군가에게 내 제안을 요청할때 사용한다.
예문) 해석참고용
  • Shall I open the window? (= Do you want me to open the window?)
    저 창문을 열어도 될까요? (= 저 창문을 내가 열기를 원하나요?)
  • I've got no money. What shall I do? (= What do you suggest?)
    나는 돈이 없어. 내가 뭘하면 될까? (= 뭘 제안할래요?)
  • Shall we go? Just a minute. I'm not ready yet.
    갈까? 조금만 기다려. 아직 준비가 안됬어.
  • Where shall we have lunch? Let's go to Marino's.
    어디에서 점심을 먹을까요? Marino's로 갑시다.

Compare

예문) 해석참고용
  • Shall I shut the door? (= Do you want me to shut it?)
    내가 그 문을 닫아도 돼? (= 내가 그 문을 닫기를 원하니?)
  • Will you shut the door? (= I want you to shut it.)
    그 문좀 닫아줄래? (= 나는 너가 그 문을 닫기를 원한다.)


Read more ...

2019년 5월 25일 토요일

[leetcode] 66. Plus One

원문)
Given a non-empty array of digits representing a non-negative integer, plus one to the integer.
The digits are stored such that the most significant digit is at the head of the list, and each element in the array contain a single digit.
You may assume the integer does not contain any leading zero, except the number 0 itself.

번역)
양수의 값이 있는 배열이 주어졌을때 +1을 하라.
최상위 숫자가 리스트의 첫째자리에 있고 각 요소들은 한자리씩 들어가 있다.
숫자 0을 제외하고 나머지 최상위 자리에는 0이 들어갈 수 없다고 가정하라.


예제)


Example 1:
Input: [1,2,3]
Output: [1,2,4]
Explanation: The array represents the integer 123.
Example 2:
Input: [4,3,2,1]
Output: [4,3,2,2]
Explanation: The array represents the integer 4321.


문제접근)
각 요소는 한자리 숫자만 들어갈 수 있다.
만약 10이면 1, 0 이렇게 2자리로 들어가야 한다.
우선 최하위 부터 자릿수 이동이 일어나야 하므로 기존 리스트를 뒤집어주고
10이 넘어가면 carry를 올려줘서
최종적으로 carry가 있을경우는 자릿수를 하나 더 올려준다.

코드)


class Solution:
    def plusOne(self, digits: List[int]) -> List[int]:
        digits = digits[::-1]
        digits[0] += 1
        carry = 0

        for i in range(len(digits)):
            if carry:
                digits[i] += 1
                carry = 0
                
            carry = digits[i] // 10
            digits[i] = digits[i] % 10
        
        if carry:
            digits.append(1)
        return digits[::-1]

Read more ...

[leetcode] 747. Largest Number At Least Twice of Others

원문)
In a given integer array nums, there is always exactly one largest element.
Find whether the largest element in the array is at least twice as much as
every other number in the array.
If it is, return the index of the largest element, otherwise return -1.

번역)
정수 배열이 주어지고, 그곳에는 가장 큰 요소가 있다.
해당 가장 큰 요소는 그 다음 큰 수의 두배가 넘어야 한다.
만약 있다면 그 해당 index를 반환하고 아니라면 -1를 반환하라.


예제)


Example 1:
Input: nums = [3, 6, 1, 0]
Output: 1
Explanation: 6 is the largest integer, and for every other number in the array x,
6 is more than twice as big as x.  The index of value 6 is 1, so we return 1.

Example 2:
Input: nums = [1, 2, 3, 4]
Output: -1
Explanation: 4 isn't at least as big as twice the value of 3, so we return -1.

Note:
  1. nums will have a length in the range [1, 50].
  2. Every nums[i] will be an integer in the range [0, 99].

문제접근)

  1. 리스트를 하나 복사해두고 max하나 최대값 빼고 다음 max값구해서
    m1, m2를 구하고 원본 리스트에서 index를 구하여 계산한다.
  2. 리스트를 복사하는것이 마음에 걸려서 조금더 찾아보니
    최대값을 구해두고 그 값을 이용하여 index를 구하고 나머지들끼리 max를 구한다.


코드)

1. 접근

class Solution:
    def dominantIndex(self, nums: List[int]) -> int:
        if len(nums) < 2:
            return 0
        tmp = nums.copy()
        m1 = max(tmp)
        tmp.remove(m1)
        m2 = max(tmp)
        index = nums.index(m1)
        
        if m1 >= m2 * 2:
            return index
        else:
            return -1

2. 접근


class Solution:
    def dominantIndex(self, nums: List[int]) -> int:
        m1 = max(nums)
        m2 = 0
        
        index = -1
        l = len(nums)
        for i in range(l):
            if nums[i] == m1:
                index = i
            else:
                m2 = max(m2, nums[i])
                
        if m1 >= m2 * 2:
            return index
        else:
            return -1


Read more ...

[leetcode] 724. Find Pivot Index

원문)
Given an array of integers nums, write a method that returns the "pivot" index of this array.
We define the pivot index as the index where the sum of the numbers to the left of the index is equal to the sum of the numbers to the right of the index.
If no such index exists, we should return -1.
If there are multiple pivot indexes, you should return the left-most pivot index.

번역)
정수 숫자의 배열이 주어졌을때 배열의 "pivot" 인덱스를 구하라.
"pivot"은 인덱스의 왼쪽 숫자들의 합과 인덱스의 오른쪽 숫자들의 합이 동일한 index를
뜻한다.
만약 없다면 -1을 반환.
만약 여러개라면 가장 왼쪽의 pivot 인덱스를 반환.


예제)


Example 1:
Input: 
nums = [1, 7, 3, 6, 5, 6]
Output: 3
Explanation: 
The sum of the numbers to the left of index 3 (nums[3] = 6) is equal 
to the sum of numbers to the right of index 3.
Also, 3 is the first index where this occurs.

Example 2:
Input: 
nums = [1, 2, 3]
Output: -1
Explanation: 
There is no index that satisfies the conditions in the problem statement.

Note:
  • The length of nums will be in the range [0, 10000].
  • Each element nums[i] will be an integer in the range [-1000, 1000].

문제접근)
1. 접근
  • 다 되었다고 생각했는데, 느리다.
    왜 느리냐 생각해보니 sum을 계속한다 두번씩.
2. 접근

  • 왼쪽부터 더해주니까 그부분은 sum을 지웠다만 역시나 느린가 봄..
3. 접근

  • 총합을 구할 수 있다.
    그리고 접근 2의 l_sum을 가지고 있으니 r_sum도 구할 수 있다.


코드)

1. 접근

class Solution:
    def pivotIndex(self, nums: List[int]) -> int:
        l = len(nums)
        
        if l == 0:
            return -1
        if 0 == sum(nums[1:]):
            return 0
        
        for i in range(1, l):
            l = nums[:i]
            r = nums[i+1:]
            if sum(l) == sum(r):
                return i
        return -1

2. 접근

class Solution:
    def pivotIndex(self, nums: List[int]) -> int:
        l = len(nums)
        
        if l == 0:
            return -1
        if 0 == sum(nums[1:]):
            return 0
        
        l_sum = nums[0]
        for i in range(1, l):
            r = nums[i+1:]
            if l_sum == sum(r):
                return i
            l_sum += nums[i]
        return -1

3. 접근


class Solution:
    def pivotIndex(self, nums: List[int]) -> int:
        l = len(nums)
        t_sum = sum(nums)
        
        if l == 0:
            return -1
        if 0 == sum(nums[1:]):
            return 0
        
        l_sum = nums[0]
        for i in range(1, l):
            if l_sum == t_sum - l_sum - nums[i]:
                return i
            l_sum += nums[i]
        return -1

Read more ...