Use var as the type of any local variable declaration (even in a for statement), and the type will be inferred from the initializing expression (any further assignments to the variable are not involved in this type inference).
For example: var x = 10.0; will infer double, and var y = new ArrayList<String>(); will infer ArrayList<String>.
Note that this is an annotation type because var x = 10; will be desugared to @var int x = 10;
Complete documentation is found at the project lombok features page for @var .
var 사용법에 적힌 저 'will be desugared to '의 뜻이 무엇일까 찾아보니 간결하게 표기된 문장(슈가링된 문장)을 다시 원래대로 돌린다는 뜻이었다. (흥미로웠지만 문제를 해결할만한 단서는 아니었다. )
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.2/install.sh | bash
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 15916 100 15916 0 0 39592 0 --:--:-- --:--:-- --:--:-- 39592
=> Downloading nvm from git to '/Users/seungmikim/.nvm'
=> Cloning into '/Users/seungmikim/.nvm'...
remote: Enumerating objects: 356, done.
remote: Counting objects: 100% (356/356), done.
remote: Compressing objects: 100% (303/303), done.
remote: Total 356 (delta 39), reused 164 (delta 27), pack-reused 0
Receiving objects: 100% (356/356), 222.15 KiB | 1.30 MiB/s, done.
Resolving deltas: 100% (39/39), done.
* (HEAD detached at FETCH_HEAD)
master
=> Compressing and cleaning up git repository
=> Appending nvm source string to /Users/seungmikim/.zshrc
=> Appending bash_completion source string to /Users/seungmikim/.zshrc
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
=> You currently have modules installed globally with `npm`. These will no
=> longer be linked to the active version of Node when you install a new node
=> with `nvm`; and they may (depending on how you construct your `$PATH`)
=> override the binaries of modules installed with `nvm`:
/usr/local/lib
├── corepack@0.10.0
=> If you wish to uninstall them at a later point (or re-install them under your
=> `nvm` Nodes), you can remove them from the system Node as follows:
$ nvm use system
$ npm uninstall -g a_module
=> Close and reopen your terminal to start using nvm or run the following to use it now:
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
(base) ~ nvm --version
zsh: command not found: nvm
1. channel이 100이면 그냥 리턴한다. 2. 모든 버튼이 다 고장 나면 +,- 로만 이동한다 3-1. channel로 이동할 수 있는 버튼이 있으면 그 버튼을 누른다. 3-2. 그 버튼이 없으면 제일 가까운 버튼을 찾아 누르고 3단계를 종료한다 4 3단계를 진행했는데 버튼의 개수가 channel의 개수보다 작으면 적절한 키를 찾아 나머지 자릿수를 채운다 4-1 만약 이미 선택한 버튼으로 내가 보고싶은 채널 이상이 만들어진다면 나머지 키는 현재 누를 수 있는 버튼의 제일 작은 값으로 채운다 4-2 만약 이미 선택한 버튼으로 내가 보고싶은 채널 이하로 만들어진다면 나머지 키는 현재 누를 수 있는 버튼의 제일 큰 값으로 채운다 5. 누를 버튼이 만들어졌으면 +나 - 개수를 센다. 이때 절댓값을 이용한다 6.+,-로만 이동하는 경우와 숫자버튼을 눌러 +-로 이동하는 경우 중 더 작은 값을 리턴한다
import sys
# from collections import deque
channel=input()
button=['0','1','2','3','4','5','6','7','8','9']
m=int(input())
#고장난 버튼 없음
if m==0:
print(len(channel))
sys.exit()
broken_set=set(input().split())
button=list(set(button)-broken_set)
now='100'
if channel==now:
print(0)
sys.exit()
# 모든 숫자 버튼이 다 고장남
if not button:
print(abs(int(channel)-int(now)))
sys.exit()
press_num=[]
for c in list(channel):
if c in button:
press_num.append(c)
else:
min_diff=10
replace_button=c
for b in button:
if min_diff>abs(int(c)-int(b)):
replace_button=b
min_diff=abs(int(c)-int(b))
press_num.append(replace_button)
break
if len(channel)>len(press_num):
index=len(press_num)-1
if int(press_num[index])>int(channel[index]):
add_num=str(min(map(int,button)))
else:
add_num=str(max(map(int,button)))
while len(channel)>len(press_num):
press_num.append(add_num)
tmp=int(''.join(press_num))
print(min(abs(tmp-int(channel))+len(channel) ,abs(int(channel)-int(now))))
from collections import deque
def dfs(graph,v,visited):
visited[v]=True
print(v, end=" ")
for i in graph[v]:
if not visited[i]:
dfs(graph,i,visited)
def bfs(graph,v,visited):
queue=deque([v])
visited[v]=True
while queue:
node=queue.popleft()
print(node,end=' ')
for i in graph[node]:
if not visited[i]:
queue.append(i)
visited[i]=True
n,m,v=map(int, input().split())
graph=[[] for _ in range(0,n+1)]
#양 방향의 간선
for _ in range(m):
a,b=map(int, input().split())
graph[a].append(b)
graph[b].append(a)
#두 노드를 잇는 간선이 중복되서 들어올 수 있기 때문에 set()으로 중복제거
#숫자가 작은 노드를 먼저 선택해야 하므로 그래프를 정렬했다.
for i in range(n+1):
graph[i]=sorted(list(set(graph[i])))
print(graph)
visited=[False]*(n+1)
dfs(graph,v,visited)
print()
visited=[False]*(n+1)
bfs(graph,v,visited)
정석 코드 그대로 dfs는 재귀로 풀고 bfs는 큐로 풀면 된다.
왜 이렇게 많이 틀렸냐 하면
1. 오타를 낸 상태로 그대로 제출
2. 양 방향 간선임을 고려 안 하고 제출
3. 같은 간선이 중복으로 들어오는 경우와 그 간선을 방문할 때 작은 숫자를 먼저 방문해야 하는 경우를 고려하지 못함
def solution(number, k):
number=list(number)
stack=[]
stack.append(number.pop(0))
while k>0:
num=number.pop(0)
if num<=stack[-1]:
stack.append(num)
else:
while stack and stack[-1]<num and k>0:
stack.pop()
k-=1
stack.append(num)
return ''.join(stack+number)
스택을 하나 만들어 number를 숫자 앞에서 부터 하나씩 빼서 스택에 push 한다. 그리고 스택의 최상단의 값과 number에서 하나씩 뽑은 값을 비교해 스택의 최상단의 값이 작으면 제거한다. 이때 제거하는 수만큼 k에서 -1씩 하고 k개만큼 숫자를 빼면 종료한다.
테스트 10은 시간 초과로 실패하고 테스트 12는 런타임 에러가 났다.
테스트 12 런타임 에러 해결 : 만약 처음에 주어진 수가 87654321처럼 앞자리가 늘 큰 수면 위의 코드에서 런타임 에러가 난다. k가 감소하는 경우에 걸리지 않기 때문이다. 그러므로 k>0이고 number에 pop()할 거리가 남아있을 때까지만 while문을 돌리고 만약 while문 이후에서 k가 0보다 크다면 맨 뒷 수를 k개만큼 빼주면 된다
수정된 코드
def solution(number, k):
number=list(number)
stack=[]
stack.append(number.pop(0))
while k>0 and number:
num=number.pop(0)
if num==9:
stack.append(num)
continue
if num<=stack[-1]:
stack.append(num)
else:
while stack and stack[-1]<num and k>0:
stack.pop()
k-=1
stack.append(num)
stack=stack+number
while k>0:
stack.pop()
k-=1
return ''.join(stack)
쉽게 풀리지 않는 테/케 10 ^^
테스트 10 해결 : 우선 구글링을 한 결과 테스트 10은 숫자가 9인 경우 바로 추가하고 다음 단계로 가야 한다고 했다. 위의 코드에도 그렇게 하도록 했는데 안된 걸 보면 내 코드에 군더더기가 좀 많았나 보다. 그래서 좀 더 고심해서 깔끔하게 코드를 손 봐주었다. 우선 마지막에 k가 0보다 클 경우 어차피 숫자 뒷부분을 잘라내줄 것이므로 차라리 number 전체를 순회하는 것이 더 나을 것이라고 생각되었다. 전체 while 문을 그냥 for문으로 변경하고 그에 맞게 내부 코드도 수정해 주었다.
def solution(number, k):
stack=[]
for n in number:
if n==9:
stack.append(n)
continue
while stack and stack[-1]<n and k:
stack.pop()
k-=1
stack.append(n)
while k:
stack.pop()
k-=1
return ''.join(stack)