Reverse3 [leetcode 189] Rotate Array Given an array, rotate the array to the right by k steps, where k is non-negative. Follow up: Try to come up as many solutions as you can, there are at least 3 different ways to solve this problem. Could you do it in-place with O(1) extra space? Example 1: Input: nums = [1,2,3,4,5,6,7], k = 3 Output: [5,6,7,1,2,3,4] Explanation: rotate 1 steps to the right: [7,1,2,3,4,5,6] rotate 2 steps to the .. 2020. 11. 16. [leetcode 48] Rotate Image You are given an n x n 2D matrix representing an image, rotate the image by 90 degrees (clockwise). You have to rotate the image in-place, which means you have to modify the input 2D matrix directly. DO NOT allocate another 2D matrix and do the rotation. Example 1: Input: matrix = [[1,2,3],[4,5,6],[7,8,9]] Output: [[7,4,1],[8,5,2],[9,6,3]] Example 2: Input: matrix = [[5,1,9,11],[2,4,8,10],[13,3,.. 2020. 11. 9. [leetcode 234] Palindrome Linked List Given a singly linked list, determine if it is a palindrome. Example 1: Input: 1->2 Output: false Example 2: Input: 1->2->2->1 Output: true Follow up: Could you do it in O(n) time and O(1) space? 문제 풀이: 첨에 follow up을 무시하고 풀었다. 어떻게 거꾸로 돌지?해서 무시함 ㅇㅇ 첫 번째 방법(c++): 연결리스트를 모두 벡터에 집어넣고 전체 길이가 홀수/짝수일때를 나눠서 가운데부터 비교한다. /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *n.. 2020. 10. 31. 이전 1 다음