LeetCode OJ--Rotate List】的更多相关文章

博客搬至blog.csgrandeur.com,cnblogs不再更新. 新的题解会更新在新博客:http://blog.csgrandeur.com/2014/01/15/LeetCode-OJ-Solution/ ———————————————————————————————————————— ———————————————————————————————————————— LeetCode OJ 题解 LeetCode OJ is a platform for preparing tech…
Problem Link: http://oj.leetcode.com/problems/interleaving-string/ Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2. For example, Given: s1 = "aabcc", s2 = "dbbca", When s3 = "aadbbcbcac", return t…
Problem link: http://oj.leetcode.com/problems/reverse-words-in-a-string/ Given an input string, reverse the string word by word. For example, Given s = "the sky is blue", return "blue is sky the". LeetCode OJ supports Python now! The s…
一直没有系统地学习过算法,不过算法确实是需要系统学习的.大二上学期,在导师的建议下开始学习数据结构,零零散散的一学期,有了链表.栈.队列.树.图等的概念.又看了下那几个经典的算法——贪心算法.分治算法.动态规划以及回溯算法.不过,都是知其一不知其二的一知半解.到最后,发现学到了一堆的一知半解,在学校课程开这门课时,却又是不得不再学一遍.学一样东西,又不全心全意地主动去把它学好,到最后只是花费了时间,却没真真学到东西.所以,不求学识有多广,但求所学的都精. 一个偶然的机会,让我在网上找到了一本社区…
Serialization is the process of converting a data structure or object into a sequence of bits so that it can be stored in a file or memory buffer, or transmitted across a network connection link to be reconstructed later in the same or another comput…
leetcode - 48. Rotate Image - Medium descrition You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). Note: You have to rotate the image in-place, which means you have to modify the input 2D matrix direct…
常泡LC的朋友知道LC是不提供代码打包下载的,不像一般的OJ,可是我不备份代码就感觉不舒服- 其实我想说的是- 我自己写了抓取个人提交代码的小工具,放在GitCafe上了- 不知道大家有没有兴趣 https://gitcafe.com/aaronzhou/ ... ssion 拿Java写的,也打了一个包,本地有JRE环境就能运行,欢迎拍砖 抓取 LeetCode OJ 个人提交的代码 Gradle 构建项目 HttpClient.jsoup 抓取.解析网页 使用说明 进入release文件夹…
题目: Given a 2D binary matrix filled with 0's and 1's, find the largest square containing all 1's and return its area. For example, given the following matrix: 1 0 1 0 0 1 0 1 1 1 1 1 0 0 1 0 Return 4. 题目链接:https://leetcode.com/problems/maximal-square…
Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 to 3999. 给定一个整数,将他转换到罗马字符.同样这里的罗马字符不会超过1000(M),PS:关于罗马字符的介绍看我的这篇文章 :LeetCode OJ:Roman to Integer(转换罗马字符到整数) 这里的大体思路是这样的,例如对于罗马字符952来说,起答题的可以分成三个组成部分, 就…
Serialization is the process of converting a data structure or object into a sequence of bits so that it can be stored in a file or memory buffer, or transmitted across a network connection link to be reconstructed later in the same or another comput…
Given a linked list, rotate the list to the right by k places, where k is non-negative. Example 1: Input: 1->2->3->4->5->NULL, k = 2 Output: 4->5->1->2->3->NULL Explanation: rotate 1 steps to the right: 5->1->2->3-&g…
You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). Follow up:Could you do this in-place? [题目解析] 这个题目的要求是把一个二维数组向右旋转九十度,就地实现. [思路1] 相比较矩阵的转置,矩阵的旋转有什么不同呢?看下面的例子: 1,2,3 1,3,2      1,2,3 2,3,1 3,2,1    ---…
Rotate an array of n elements to the right by k steps. For example, with n = 7 and k = 3, the array [1,2,3,4,5,6,7] is rotated to [5,6,7,1,2,3,4]. Note:Try to come up as many solutions as you can, there are at least 3 different ways to solve this pro…
Given a list, rotate the list to the right by k places, where k is non-negative. For example:Given 1->2->3->4->5->NULL and k = 2,return 4->5->1->2->3->NULL. 这个题目的大意是要把链表的尾部的k节点旋转到头部,但是k可能大于链表的长度.此时要旋转的长度就是k%list.length. 解决这个问…
Given a list, rotate the list to the right by k places, where k is non-negative. For example:Given 1->2->3->4->5->NULL and k = 2,return 4->5->1->2->3->NULL. 将链表从右边数第k个开始后面的全部交换到链表的左侧.例如对于1,2,3,4,5,6 和 k = 2,就有交换之后的节点就是5,6,1,2…
You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). Follow up:Could you do this in-place?题目要就地算法,那么可以通过折叠矩阵上下以及斜对角线折叠来实现,代码如下: class Solution { public: void rotate(vector<vector<int>>& matrix…
Rotate an array of n elements to the right by k steps. For example, with n = 7 and k = 3, the array [1,2,3,4,5,6,7] is rotated to [5,6,7,1,2,3,4]. 将数组的内容倒置,看例子就知道是什么意思: class Solution { public: void rotate(vector<int>& nums, int k) { if(k > n…
189. Rotate Array Total Accepted: 55073 Total Submissions: 278176 Difficulty: Easy Rotate an array of n elements to the right by k steps. For example, with n = 7 and k = 3, the array [1,2,3,4,5,6,7] is rotated to [5,6,7,1,2,3,4]. Note: Try to come up…
Valid Palindrome吐槽一下Leetcode上各种不定义标准的输入输出(只是面试时起码能够问一下输入输出格式...),此篇文章不是详细的题解,是自己刷LeetCode的一个笔记吧,尽管没有代码,可是略微难一点的都会标出主要思路,便于以后复习 PS:题目中有"水题"两字的都是一遍AC,没有标注的都说明了问题,顺序依照Leetcode上时间倒序排列,少量题目因为和之前的题目有相关性,因此将其放在一起,比方12题和13题,因此中间可能会"缺少"几道题目,缺少的…
Problem Link: https://oj.leetcode.com/problems/validate-binary-search-tree/ We inorder-traverse the tree, and for each node we check if current_node.val > prev_node.val. The code is as follows. # Definition for a binary tree node # class TreeNode: #…
Problem Link: https://oj.leetcode.com/problems/recover-binary-search-tree/ We know that the inorder traversal of a binary search tree should be a sorted array. Therefore, we can compare each node with its previous node in the inorder to find the two…
Problem Link: https://oj.leetcode.com/problems/same-tree/ The following recursive version is accepted but the iterative one is not accepted... # Definition for a binary tree node # class TreeNode: # def __init__(self, x): # self.val = x # self.left =…
Problem Link: https://oj.leetcode.com/problems/symmetric-tree/ To solve the problem, we can traverse the tree level by level. For each level, we construct an array of values of the length 2^depth, and check if this array is symmetric. The tree is sym…
Problem Link: https://oj.leetcode.com/problems/binary-tree-level-order-traversal/ Traverse the tree level by level using BFS method. # Definition for a binary tree node # class TreeNode: # def __init__(self, x): # self.val = x # self.left = None # se…
Problem Link: https://oj.leetcode.com/problems/binary-tree-zigzag-level-order-traversal/ Just BFS from the root and for each level insert a list of values into the result. # Definition for a binary tree node # class TreeNode: # def __init__(self, x):…
Problem Link: https://oj.leetcode.com/problems/maximum-depth-of-binary-tree/ Simply BFS from root and count the number of levels. The code is as follows. # Definition for a binary tree node # class TreeNode: # def __init__(self, x): # self.val = x #…
Problem Link: https://oj.leetcode.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal/ The basic idea is same to that for Construct Binary Tree from Inorder and Postorder Traversal. We solve it using a recursive function. First, we…
Problem Link: https://oj.leetcode.com/problems/construct-binary-tree-from-inorder-and-postorder-traversal/ This problem can be easily solved using recursive method. By given the inorder and postorder lists of the tree, i.e. inorder[1..n] and postorde…
Problem Link: https://oj.leetcode.com/problems/binary-tree-level-order-traversal-ii/ Use BFS from the tree root to traverse the tree level by level. The python code is as follows. # Definition for a binary tree node # class TreeNode: # def __init__(s…
Problem Link: http://oj.leetcode.com/problems/convert-sorted-array-to-binary-search-tree/ Same idea to Convert Sorted Array to Binary Search Tree, but we use a recursive function to construct the binary search tree. # Definition for a binary tree nod…