Given a string s and an integer array indices of the same length.
The string s will be shuffled such that the character at the ith position moves to indices[i] in the shuffled string.
Return the shuffled string.
class Solution:
def restoreString(self, s: str, indices: List[int]) -> str:
j = 0
string = [""]*len(s)
for i in range(len(indices)):
string[indices[i]] = s[j]
j += 1
return ''.join(string)
indices
순서대로 string
리스트에 문자를 저장한 후 str 형태로 return
On a 2D plane, there are n points with integer coordinates points[i] = [xi, yi]. Return the minimum time in seconds to visit all the points in the order given by points.
You can move according to these rules:
class Solution:
def minTimeToVisitAllPoints(self, points: List[List[int]]) -> int:
a = points[0]
result = 0
for i in range(1, len(points)):
result += max(abs(points[i][1] - a[1]), abs(points[i][0] - a[0]))
a = points[i]
return result
이거 정말 별거 아닌데 쫄아서 시간을 낭비함..
그리고 왜인지 모르겠는데 점의 개수랑 헷갈려가지고 첨엔 잘 안됐다는 점..ㅎ
가로, 세로, 대각선으로 움직여야 하는 경우를 모두 분리했었음
그냥 x
끼리의 차이값이랑 y
끼리의 차이값 중에 최댓값을 return 하면 됐다..^^