LeetCode 刷题方法

##############################################

"""
刷题不能蛮干,要掌握科学的方法,否则容易打击自信心,
1,看不懂是正常的,看懂了解不出来也是正常的,千方百计解出来了后面复习又不会了也是正常的,
2,题型基本三种,数据结构,算法,算法思想,注重基础,建立list,反复联系,总结,

刷题两个目的
1,面试
2,同时提升编码能力

两个目的方法不一样
1,面试,你就先去刷热门题,热门面试题,
2,单纯的提升编码能力,分类刷

刷题步骤,
1,拿到题,先看懂题目,看不懂题目就有问题了,总结哪里的问题,
2,然后分析解法,如果没有思路就有问题了,总结哪里出了问题,
3,把思路转换成为代码,动手coding,coding不出来就有问题了,总结哪里出了问题,

注意几点:
1,分类总结,一定分类,一定要按类型总结,
2,打好基础,不要追求困难,把容易和中等刷好,笔试也不过是到中等,
3,动手操作,不要以为看懂了就不去动手coding,看懂和写出来是两码事,
4,重复练习,不要数量,刷题就要重复,掌握理念方法,而不是数量,

"""

#######################################

###########################################

#######################################

###########################################

原文地址:https://www.cnblogs.com/andy0816/p/12407519.html

时间: 2024-08-30 17:18:15

LeetCode 刷题方法的相关文章

【leetcode刷题笔记】Sum Root to Leaf Numbers

Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number. An example is the root-to-leaf path 1->2->3 which represents the number 123. Find the total sum of all root-to-leaf numbers. For example, 1 / 2 3 T

【leetcode刷题笔记】Path Sum

Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum. For example:Given the below binary tree and sum = 22, 5 / 4 8 / / 11 13 4 / \ 7 2 1 return true, as t

【leetcode刷题笔记】Max Points on a Line

Given n points on a 2D plane, find the maximum number of points that lie on the same straight line. 题解: 思路比较简单,每条直线都可以表示为y=kx+b,所以对于任意三点,如果它们共线,那么它们中任意两点的斜率都相等. 所以就遍历points数组,对其中的每一个元素计算它和位于它后面的数组元素的斜率并保存在一个hashmap中. 这个hashmap的键就是两点构成直线的斜率,值就是和当前元素po

Leetcode刷题录之Two Sum

题意大概是给出一个数列num,和一个目标数target,然后要找出数列中的两个数,使得这两个数之和等于目标数,输出这两个数的下标值(从1开始算). 一个比较暴力的方法是用一个二重循环直接遍历序列,在第一重循环中找到a,在第二重循环中找到b,使得a+b=target,这种做法的时间复杂度是O(n^2), 提交时提示超时. 改进方法,先对数列num复制一个副本,然后对副本进行排序.在一重循环中找到a,接着对这个有序的副本进行二分查找,找到b= target-a,二分查找的 时间复杂度是O(logn)

【leetcode刷题笔记】Maximal Rectangle

Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and return its area. 题解,很巧妙的一道题,对于一个0-1矩阵,它的每一行及以上都可以看作一个直方图(如下图所示),利用Largest Rectangle in Histogram的方法,可以在O(n)的时间搜索出这一行及以上的直方图中面积最大的矩形,对矩阵的每一行依次做这个操作,就可

【leetcode刷题笔记】Roman to Integer

Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 to 3999. 题解:转换的方法:从左往右扫描罗马字符,如果当前的字符对应的数字比上一个数字小,就直接加上这个数字:否则加上这个数字并且减去上一个数字的两倍,然后更新上一个数字.利用一个HashMap存放罗马字符和数字的对应. 罗马数字和阿拉伯数字的对应表格参见http://www.cnblogs.

【leetcode刷题笔记】Pow(x, n)

Implement pow(x, n). 题解:注意两点: 普通的递归把n降为n-1会超时,要用二分的方法,每次把xn = x[n/2] * x[n/2] * xn-[n/2]*2, [n/2]表示n除以2下取整. n有可能取负数,负数的时候,先计算pow(x,-n),然后返回1/pow(x,-n); 代码如下: 1 public class Solution { 2 public double pow(double x, int n) { 3 if(n == 0) 4 return 1; 5

【leetcode刷题笔记】Palindrome Partitioning

Given a string s, partition s such that every substring of the partition is a palindrome. Return all possible palindrome partitioning of s. For example, given s = "aab",Return [ ["aa","b"], ["a","a","

【leetcode刷题笔记】Recover Binary Search Tree

Two elements of a binary search tree (BST) are swapped by mistake. Recover the tree without changing its structure. Note:A solution using O(n) space is pretty straight forward. Could you devise a constant space solution? 题解:需要找到二叉搜索树中乱序的两个节点,并把它们交换回来