566. Reshape the Matrix |
Easy |
变长数组,求余法,维护行列计算在新的数组中的位置 |
https://blog.csdn.net/fuxuemingzhu/article/details/83626519 |
567. Increasing Order Search Tree |
Easy |
直接中序遍历的结果放到链表结尾 |
https://blog.csdn.net/fuxuemingzhu/article/details/82349263 |
568. Jewels and Stones |
Easy |
字典统计次数 |
https://blog.csdn.net/fuxuemingzhu/article/details/79188903 |
569. Unique Email Addresses |
Easy |
字符串+set统计个数 |
https://blog.csdn.net/fuxuemingzhu/article/details/83478570 |
570. To Lower Case |
Easy |
ASIIC码操作ord,chr |
https://blog.csdn.net/fuxuemingzhu/article/details/81015228 |
571. Unique Morse Code Words |
Easy |
字典映射 + set统计个数 |
https://blog.csdn.net/fuxuemingzhu/article/details/79774003 |
572. Sort Array By Parity |
Easy |
自定义sorted函数的cmp为数字mod 2 |
https://blog.csdn.net/fuxuemingzhu/article/details/82732066 |
573. Hamming Distance |
Easy |
先异或 再数1的个数 |
https://blog.csdn.net/fuxuemingzhu/article/details/54138423 |
574. Robot Return to Origin |
Easy |
Counter统计,判断是否相等 |
https://blog.csdn.net/fuxuemingzhu/article/details/83663650 |
575. Flipping an Image |
Easy |
直接计算新的数组的每个位置的值即可 |
https://blog.csdn.net/fuxuemingzhu/article/details/80471495 |
576. Merge Two Binary Trees |
Easy |
树的递归操作 |
https://blog.csdn.net/fuxuemingzhu/article/details/79052953 |
577. Implement strStr() |
Easy |
字符串遍历+切片是否相等的判断 |
https://blog.csdn.net/fuxuemingzhu/article/details/79254558 |
578. Find and Replace Pattern |
Easy |
直接使用字典做映射 |
https://blog.csdn.net/fuxuemingzhu/article/details/82014687 |
579. Binary Tree Pruning |
Medium |
二叉树的后序遍历 |
https://blog.csdn.net/fuxuemingzhu/article/details/79858752 |
580. Array Partition I |
Easy |
排序+求和 |
https://blog.csdn.net/fuxuemingzhu/article/details/71412574 |
581. Self Dividing Numbers |
Easy |
直接遍历区间的每个数字进行判断 |
https://blog.csdn.net/fuxuemingzhu/article/details/79053113 |
582. Peak Index in a Mountain Array |
Easy |
二分查找的变种,使用Mid位置和左右位置比较 |
https://blog.csdn.net/fuxuemingzhu/article/details/80721162 |
583. Sort Array By Parity II |
Easy |
分别求出奇偶数组然后拼接 |
https://blog.csdn.net/fuxuemingzhu/article/details/83045735 |
584. Projection Area of 3D Shapes |
Easy |
分别计算三视图的面积即可 |
https://blog.csdn.net/fuxuemingzhu/article/details/81748335 |
585. Smallest Range I |
Easy |
直接数学计算 |
https://blog.csdn.net/fuxuemingzhu/article/details/82824685 |
586. Transpose Matrix |
Easy |
先构建数组再遍历实现翻转 |
https://blog.csdn.net/fuxuemingzhu/article/details/81015450 |
587. N-ary Tree Preorder Traversal |
Easy |
多叉树的先序遍历,可以用递归和迭代 |
https://blog.csdn.net/fuxuemingzhu/article/details/81021950 |
588. N-ary Tree Postorder Traversal |
Easy |
多叉树的后序遍历 |
https://blog.csdn.net/fuxuemingzhu/article/details/81017965 |
589. Intersection of Two Arrays II |
Easy |
先排序然后用两个指针移动找出数组交集 |
https://blog.csdn.net/fuxuemingzhu/article/details/54341965 |
590. Middle of the Linked List |
Easy |
快慢指针同时向链表后面移动 |
https://blog.csdn.net/fuxuemingzhu/article/details/81748484 |
591. Search in a Binary Search Tree |
Easy |
BST中节点的查找,递归 |
https://blog.csdn.net/fuxuemingzhu/article/details/81015754 |
592. Number of Recent Calls |
Easy |
找出满足一定条件的区间长度,可以使用二分或者队列 |
https://blog.csdn.net/fuxuemingzhu/article/details/83714891 |
593. Maximum Depth of N-ary Tree |
Easy |
求树的高度,可以使用BFS和DFS |
https://blog.csdn.net/fuxuemingzhu/article/details/81021864 |
594. Reverse Words in a String III |
Easy |
字符串的单词分别翻转再拼接到一起就好了 |
https://blog.csdn.net/fuxuemingzhu/article/details/70141268 |
595. Number of Lines To Write String |
Easy |
使用字典保存每个字符的长度,然后统计每行的长度是否超过100就好了 |
https://blog.csdn.net/fuxuemingzhu/article/details/79810381 |
596. Reverse String |
Easy |
字符串翻转,[::-1 |
https://blog.csdn.net/fuxuemingzhu/article/details/51284382 |
597. Subdomain Visit Count |
Easy |
字典保存每个子域名出现的次数即可 |
https://blog.csdn.net/fuxuemingzhu/article/details/79789925 |
598. Number Complement |
Easy |
求数字的补数,方法是异或上与其二进制数字的长度相等的全1二进制数 |
https://blog.csdn.net/fuxuemingzhu/article/details/54562124 |
599. Shortest Distance to a Character |
Easy |
过两遍数组,分别找出距离左边和右边的这个字符的最短距离 |
https://blog.csdn.net/fuxuemingzhu/article/details/80471765 |
600. Keyboard Row |
Easy |
使用字典保存每行元素,然后看每个单词是不是只由一行元素组成 |
https://blog.csdn.net/fuxuemingzhu/article/details/68953517 |
601. Groups of Special-Equivalent Strings |
Easy |
把奇偶位置都取出来,重新拼接成字符串作为指纹,看总的有多少种指纹 |
https://blog.csdn.net/fuxuemingzhu/article/details/82083609 |
602. Leaf-Similar Trees |
Easy |
先序、中序、后序都能得到叶子序列 |
https://blog.csdn.net/fuxuemingzhu/article/details/81748617 |
603. Uncommon Words from Two Sentences |
Easy |
使用字典统计每个单词出现的次数,然后看字典keys()的交集,然后在字典中看是不是只出现了一次 |
https://blog.csdn.net/fuxuemingzhu/article/details/81749170 |
604. Toeplitz Matrix |
Easy |
判断每个斜线是否相等,方法是判断每个元素是否和其左上角元素相等 |
https://blog.csdn.net/fuxuemingzhu/article/details/79127213 |
605. Island Perimeter |
Easy |
求小岛的周长。使用所有陆地个数×4-相交部分×2. |
https://blog.csdn.net/fuxuemingzhu/article/details/83868905 |
606. Baseball Game |
Easy |
用一个栈进行模拟 |
https://blog.csdn.net/fuxuemingzhu/article/details/79183412 |
607. Binary Gap |
Easy |
二进制表示中1的最大间距,保留上一个1的位置即可 |
https://blog.csdn.net/fuxuemingzhu/article/details/81079495 |
608. Maximum Depth of Binary Tree |
Easy |
二叉树的高度,可以用DFS和BFS |
https://blog.csdn.net/fuxuemingzhu/article/details/48490829 |
609. Single Number |
Easy |
所有的数字出现了两次,其中一个只出现了一次。找出这个数字的方法可以使用字典统计或者异或运算 |
https://blog.csdn.net/fuxuemingzhu/article/details/54173334 |
610. Next Greater Element I |
Easy |
找出某个数字右边比他大的数字,直接遍历查找就好了 |
https://blog.csdn.net/fuxuemingzhu/article/details/79080337 |
611. Average of Levels in Binary Tree |
Easy |
求每层的二叉树的均值,可以使用BFS和DFS |
https://blog.csdn.net/fuxuemingzhu/article/details/79088554 |
612. Binary Number with Alternating Bits |
Easy |
判断数字的二进制表示是不是01交错的。直接遍历判断,或者位运算。 |
https://blog.csdn.net/fuxuemingzhu/article/details/79089937 |
613. Prime Number of Set Bits in Binary Representation |
Easy |
判断二进制数字的1的个数是不是质数 |
https://blog.csdn.net/fuxuemingzhu/article/details/79089092 |
614. Reverse Only Letters |
Easy |
只翻转字母其余字符不动,可以使用栈、双指针 |
https://blog.csdn.net/fuxuemingzhu/article/details/82956271 |
615. Nim Game |
Easy |
判断输入数字是不是4的倍数即可 |
https://blog.csdn.net/fuxuemingzhu/article/details/51284421 |
616. Goat Latin |
Easy |
字符串处理,简单 |
https://blog.csdn.net/fuxuemingzhu/article/details/80471925 |
617. Surface Area of 3D Shapes |
Easy |
统计立方体个数,减去相交面积 |
https://blog.csdn.net/fuxuemingzhu/article/details/82083893 |
618. Letter Case Permutation |
Easy |
经典回溯法,把字符的大小写分别拼接到字符串尾部 |
https://blog.csdn.net/fuxuemingzhu/article/details/79360330 |
619. Add Digits |
Easy |
两重循环,一直对每位数字求和直到剩余个位数 |
https://blog.csdn.net/fuxuemingzhu/article/details/49161129 |
620. Move Zeroes |
Easy |
使用一个指针指向第一个为0的位置,然后遍历不是0的位置进行交换 |
https://blog.csdn.net/fuxuemingzhu/article/details/51284981 |
621. Shortest Completing Word |
Easy |
找出符合某个模式的字符串,直接处理就好了 |
https://blog.csdn.net/fuxuemingzhu/article/details/79432228 |
622. Employee Importance |
Easy |
dfs |
https://blog.csdn.net/fuxuemingzhu/article/details/79091343 |
623. Find the Difference |
Easy |
找多出来的字符,可以使用字典,也可以使用异或 |
https://blog.csdn.net/fuxuemingzhu/article/details/54174443 |
624. Detect Capital |
Easy |
统计大写字符的个数,判断是不是在首位 |
https://blog.csdn.net/fuxuemingzhu/article/details/68957658 |
625. Find All Numbers Disappeared in an Array |
Easy |
用set去重,找出没有出现的数字即可 |
https://blog.csdn.net/fuxuemingzhu/article/details/53981307 |
626. Count Binary Substrings |
Easy |
先找出连续的0,1个数,然后进行交错求最小值,在求和 |
https://blog.csdn.net/fuxuemingzhu/article/details/79183556 |
627. 4Sum II |
Easy |
4sum,先确定两个数字,然后看剩余两个数字的和是否出现过 |
https://blog.csdn.net/fuxuemingzhu/article/details/79473739 |
628. Rotated Digits |
Easy |
字典保存翻转后的数字,判断是否相等即可。 |
https://blog.csdn.net/fuxuemingzhu/article/details/79378135 |
629. Two Sum IV - Input is a BST |
Easy |
BFS或者DFS,在遍历的过程中进行破案吨 |
https://blog.csdn.net/fuxuemingzhu/article/details/79120732 |
630. Sum of Two Integers |
Easy |
位运算 |
https://blog.csdn.net/fuxuemingzhu/article/details/79379939 |
631. Intersection of Two Arrays |
Easy |
用两个set求交集,然后转成List即可 |
https://blog.csdn.net/fuxuemingzhu/article/details/54236183 |
632. Construct String from Binary Tree |
Easy |
先序遍历,可以省略右子树,所以需要做一个节点是否存在的判断 |
https://blog.csdn.net/fuxuemingzhu/article/details/79121550 |
633. Reverse Linked List |
Easy |
翻转单链表,可以使用递归和迭代 |
https://blog.csdn.net/fuxuemingzhu/article/details/51290121 |
634. Majority Element |
Easy |
Moore投票法,或者字典统计次数 |
https://blog.csdn.net/fuxuemingzhu/article/details/51288749 |
635. Excel Sheet Column Number |
Easy |
26进制,没有难度 |
https://blog.csdn.net/fuxuemingzhu/article/details/51286467 |
636. Roman to Integer |
Easy |
使用字典保存映射,遍历求值就好了。 |
https://blog.csdn.net/fuxuemingzhu/article/details/48208995 |
637. Reorder Log Files |
Easy |
分割排序,再拼接 |
https://blog.csdn.net/fuxuemingzhu/article/details/83961188 |
638. Best Time to Buy and Sell Stock |
Easy |
一次遍历,如果后一天比前一天大就买了卖 |
https://blog.csdn.net/fuxuemingzhu/article/details/51291151 |
639. Valid Anagram |
Easy |
判断字符串是否是同构的,直接统计词频或者排序 |
https://blog.csdn.net/fuxuemingzhu/article/details/51286195 |
640. Lemonade Change |
Easy |
贪心算法,找零钱先找大的面额,如果不够再用小的面额 |
https://blog.csdn.net/fuxuemingzhu/article/details/80913955 |
641. Contains Duplicate |
Easy |
判断数组是否有重复,可以统计词频,判断set长度是否相等,排序等方法 |
https://blog.csdn.net/fuxuemingzhu/article/details/51289768 |
642. Construct Quad Tree |
Easy |
建立四叉树,使用递归,判断4个叶子全部是0或者1 |
https://blog.csdn.net/fuxuemingzhu/article/details/81836838 |
643. Design HashMap |
Easy |
设计一个字典,直接开个很大的数组即可,内存放得下 |
https://blog.csdn.net/fuxuemingzhu/article/details/81017297 |
644. Convert BST to Greater Tree |
Easy |
把每个节点变成比它大的节点的值的和,采用逆中序遍历。 |
https://blog.csdn.net/fuxuemingzhu/article/details/79132336 |
645. Same Tree |
Easy |
判断两棵数是否相等,直接递归 |
https://blog.csdn.net/fuxuemingzhu/article/details/51285076 |
646. Minimum Absolute Difference in BST |
Easy |
中序遍历,保存前一个节点,当前节点的值减去前一个节点的值 |
https://blog.csdn.net/fuxuemingzhu/article/details/69666671 |
647. Minimum Distance Between BST Nodes |
Easy |
和上题完全一样 |
https://blog.csdn.net/fuxuemingzhu/article/details/79402127 |
648. Ransom Note |
Easy |
使用字典统计每个字符出现的次数,前者小于后者即可 |
https://blog.csdn.net/fuxuemingzhu/article/details/54178342 |
649. Rotate String |
Easy |
字符串切片 |
https://blog.csdn.net/fuxuemingzhu/article/details/79521194 |
650. 1-bit and 2-bit Characters |
Easy |
单次遍历,判断前面满足的条件下,最后一位是0即可。 |
https://blog.csdn.net/fuxuemingzhu/article/details/79130681 |
651. Minimum Moves to Equal Array Elements |
Easy |
把n-1个数字加1,相等于把最大值-1.求和-n*最小值 |
https://blog.csdn.net/fuxuemingzhu/article/details/54177981 |
652. Flood Fill |
Easy |
对相同颜色进行染色,可以使用DFS和BFS. |
https://blog.csdn.net/fuxuemingzhu/article/details/79401716 |
653. Sum of Left Leaves |
Easy |
求所有左叶子的和,要判断是不是在左边,判断是不是叶子,然后加到结果中 |
https://blog.csdn.net/fuxuemingzhu/article/details/54178595 |
654. Number of Boomerangs |
Easy |
统计回旋镖的个数,不能暴力解决,需要使用排列组合公式n*(n-1) |
https://blog.csdn.net/fuxuemingzhu/article/details/54379349 |
655. Range Addition II |
Easy |
求队列的最小值即可 |
https://blog.csdn.net/fuxuemingzhu/article/details/79398272 |
656. Construct the Rectangle |
Easy |
从算术平方根开始找约数即可 |
https://blog.csdn.net/fuxuemingzhu/article/details/68957959 |
657. Two Sum II - Input array is sorted |
Easy |
前后指针同时向中间走,找到target之后停止 |
https://blog.csdn.net/fuxuemingzhu/article/details/70232518 |
658. First Unique Character in a String |
Easy |
首先做个字符出现次数的统计,然后再次遍历,找出只出现了一次的第一个字符。 |
https://blog.csdn.net/fuxuemingzhu/article/details/84139374 |
659. Degree of an Array |
Easy |
求最大的出现次数的所有数字,其最左右出现的位置差的最小值 |
https://blog.csdn.net/fuxuemingzhu/article/details/79146067 |
660. Assign Cookies |
Easy |
贪心算法,尽可能给小孩满足其欲望的饼干 |
https://blog.csdn.net/fuxuemingzhu/article/details/54177627 |
661. Convert Sorted Array to Binary Search Tree |
Easy |
构建BST,使用中间数进行分割,用递归 |
https://blog.csdn.net/fuxuemingzhu/article/details/70665213 |
662. Relative Ranks |
Easy |
相对排名,可以使用堆或者排序或者argsort |
https://blog.csdn.net/fuxuemingzhu/article/details/70173434 |
663. Image Smoother |
Easy |
直接暴力求平均即可 |
https://blog.csdn.net/fuxuemingzhu/article/details/79156499 |
664. Longest Palindrome |
Easy |
统计出现次数的奇偶就可以 |
https://blog.csdn.net/fuxuemingzhu/article/details/54236594 |
665. Minimum Index Sum of Two Lists |
Easy |
保存出现的索引和与元素的对应,使用堆保存最小的就行 |
https://blog.csdn.net/fuxuemingzhu/article/details/79138621 |
666. Missing Number |
Easy |
理论和-当前和 |
https://blog.csdn.net/fuxuemingzhu/article/details/70332471 |
667. Binary Tree Tilt |
Easy |
后序遍历函数返回的是左右子树的差,在里面用变量求和 |
https://blog.csdn.net/fuxuemingzhu/article/details/71440281 |
668. Positions of Large Groups |
Easy |
找到长度大于3的连续字符,需要判断结束!! |
https://blog.csdn.net/fuxuemingzhu/article/details/80472242 |
669. Intersection of Two Arrays II |
Easy |
可以排序,也可以使用字典统计次数 |
https://blog.csdn.net/fuxuemingzhu/article/details/54341965 |
670. Diameter of Binary Tree |
Easy |
递归求树的深度,同时求左右两个深度的和的最大值 |
https://blog.csdn.net/fuxuemingzhu/article/details/70338312 |
671. Student Attendance Record I |
Easy |
统计A的个数,并且判断连续L的个数 |
https://blog.csdn.net/fuxuemingzhu/article/details/70337973 |
672. Best Time to Buy and Sell Stock |
Easy |
保存当前的最小值以及最大收益即可 |
https://blog.csdn.net/fuxuemingzhu/article/details/51291151 |
673. Maximum Product of Three Numbers |
Easy |
找出三个数最大的乘积 |
https://blog.csdn.net/fuxuemingzhu/article/details/79169635 |
674. Binary Watch |
Easy |
使用combinations函数 |
https://blog.csdn.net/fuxuemingzhu/article/details/54344098 |
675. Min Cost Climbing Stairs |
Easy |
动态规划 |
https://blog.csdn.net/fuxuemingzhu/article/details/79188612 |
676. Long Pressed Name |
Easy |
使用双指针,统计连续字符出现的次数 |
https://blog.csdn.net/fuxuemingzhu/article/details/83245395 |
677. Reverse String II |
Easy |
Python的切片翻转 |
https://blog.csdn.net/fuxuemingzhu/article/details/70141909 |
678. Design HashSet |
Easy |
直接开数组就行 |
https://blog.csdn.net/fuxuemingzhu/article/details/81016992 |
679. Binary Tree Level Order Traversal II |
Easy |
DFS和BFS都可以 |
https://blog.csdn.net/fuxuemingzhu/article/details/49108449 |
680. Base 7 |
Easy |
转成7进制 |
https://blog.csdn.net/fuxuemingzhu/article/details/70194688 |
681. Distinct Subsequences |
Easy |
动规,判断当前字符是否相等 |
https://blog.csdn.net/fuxuemingzhu/article/details/84228383 |
682. Merge Two Sorted Lists |
Easy |
可以使用递归或者迭代 |
https://blog.csdn.net/fuxuemingzhu/article/details/51291406 |
683. Poor Pigs |
Easy |
类似拨号键盘,多维空间求解 |
https://blog.csdn.net/fuxuemingzhu/article/details/81079261 |
684. Binary Tree Paths |
Easy |
打印二叉树的路径,使用递归和迭代 |
https://blog.csdn.net/fuxuemingzhu/article/details/71249429 |
685. Backspace String Compare |
Easy |
字符串可以退格,使用栈轻松解决 |
https://blog.csdn.net/fuxuemingzhu/article/details/80643408 |
686. Happy Number |
Easy |
递归和迭代两种做法 |
https://blog.csdn.net/fuxuemingzhu/article/details/49180507 |
687. Longest Continuous Increasing Subsequence |
Easy |
简单的动态规划 |
https://blog.csdn.net/fuxuemingzhu/article/details/79220527 |
688. Find Smallest Letter Greater Than Target |
Easy |
线性扫描或者二分 |
https://blog.csdn.net/fuxuemingzhu/article/details/79137225 |
689. Pascal’s Triangle |
Easy |
提前构造出来,然后处理每行即可 |
https://blog.csdn.net/fuxuemingzhu/article/details/51346488 |
690. Second Minimum Node In a Binary Tree |
Easy |
递归的时候找第二小值 |
https://blog.csdn.net/fuxuemingzhu/article/details/79222455 |
691. Longest Word in Dictionary |
Easy |
先排序,再找前缀是否存在。 |
https://blog.csdn.net/fuxuemingzhu/article/details/79123277 |
692. Remove Element |
Easy |
使用双指针或者标记指针使得前面都是满足要求的,后面都不满足 |
https://blog.csdn.net/fuxuemingzhu/article/details/51303161 |
693. Climbing Stairs |
Easy |
动态规划 |
https://blog.csdn.net/fuxuemingzhu/article/details/51290778 |
694. Add Strings |
Easy |
直接模拟大整数加法,需要注意进位问题 |
https://blog.csdn.net/fuxuemingzhu/article/details/54380737 |
695. Lowest Common Ancestor of a Binary Search Tree |
Easy |
BST找公共祖先,使用递归很简单 |
https://blog.csdn.net/fuxuemingzhu/article/details/51290289 |
696. Longest Harmonious Subsequence |
Easy |
统计相邻的数字是否都存在即可 |
https://blog.csdn.net/fuxuemingzhu/article/details/79233752 |
697. Symmetric Tree |
Easy |
可以使用BFS和DFS两种方法 |
https://blog.csdn.net/fuxuemingzhu/article/details/51345707 |
698. Maximum Subarray |
Easy |
动态规划找子数组最大和 |
https://blog.csdn.net/fuxuemingzhu/article/details/71101802 |
699. Most Common Word |
Easy |
正则+统计 |
https://blog.csdn.net/fuxuemingzhu/article/details/80472079 |
700. Power of Two |
Easy |
判断二进制是不是只有1个1即可 |
https://blog.csdn.net/fuxuemingzhu/article/details/51290981 |
701. Convert a Number to Hexadecimal |
Easy |
转成16进制,难点在于负数的处理:加上1<<32 |
https://blog.csdn.net/fuxuemingzhu/article/details/54426643 |
702. Remove Duplicates from Sorted List |
Easy |
递归和循环 |
https://blog.csdn.net/fuxuemingzhu/article/details/51290506 |
703. Power of Three |
Easy |
循环和迭代 |
https://blog.csdn.net/fuxuemingzhu/article/details/51290895 |
704. Number of 1 Bits |
Easy |
使用位移统计二进制个数 |
https://blog.csdn.net/fuxuemingzhu/article/details/51290376 |
705. Path Sum III |
Easy |
找路径的个数,使用DFS*2或者BFS+DFS |
https://blog.csdn.net/fuxuemingzhu/article/details/71097135 |
706. Binary Search |
Easy |
二分的模板 |
https://blog.csdn.net/fuxuemingzhu/article/details/81017415 |
707. Pascal’s Triangle II |
Easy |
原地翻转可以用倒序遍历 |
https://blog.csdn.net/fuxuemingzhu/article/details/51348629 |
708. Implement Queue using Stacks |
Easy |
两个栈实现一个队列 |
https://blog.csdn.net/fuxuemingzhu/article/details/51345762 |
709. Subtree of Another Tree |
Easy |
DFS*2或DFS+BSF |
https://blog.csdn.net/fuxuemingzhu/article/details/71440802 |
710. House Robber |
Easy |
简单dp,当前房间偷和不偷两种状态 |
https://blog.csdn.net/fuxuemingzhu/article/details/51291936 |
711. Kth Largest Element in a Stream |
Easy |
使用小根堆维护k个值,则第一个元素就是第k大元素 |
https://blog.csdn.net/fuxuemingzhu/article/details/81027116 |
712. Reverse Vowels of a String |
Easy |
使用栈进行翻转,或者使用双指针 |
https://blog.csdn.net/fuxuemingzhu/article/details/51291677 |
713. Plus One |
Easy |
使用carry表示进位 |
https://blog.csdn.net/fuxuemingzhu/article/details/51346096 |
714. Ugly Number |
Easy |
除去2,3,5因子即可 |
https://blog.csdn.net/fuxuemingzhu/article/details/49183961 |
715. Search Insert Position |
Easy |
二分查找 |
https://blog.csdn.net/fuxuemingzhu/article/details/70738108 |
716. Set Mismatch |
Easy |
使用统计次数或者直接求和计算 |
https://blog.csdn.net/fuxuemingzhu/article/details/79247916 |
717. Largest Number At Least Twice of Others |
Easy |
找出最大值,然后弹掉,再找次大值即可。 |
https://blog.csdn.net/fuxuemingzhu/article/details/79188909 |
718. Power of Four |
Easy |
递归和迭代 |
https://blog.csdn.net/fuxuemingzhu/article/details/51291091 |
719. Find Pivot Index |
Easy |
先求和,在遍历求前半部分的和,找出左边等于右边 |
https://blog.csdn.net/fuxuemingzhu/article/details/79248308 |
720. Palindrome Number |
Easy |
可以先翻转成整数,然后判断和原来的是否相等 |
https://blog.csdn.net/fuxuemingzhu/article/details/71334663 |
721. License Key Formatting |
Easy |
计算第一个分割的长度,后面都是等长的了 |
https://blog.csdn.net/fuxuemingzhu/article/details/79234075 |
722. Two Sum |
Easy |
保存已经出现过的数字的索引,当下次遍历的时候遇到了满足要求的结果,那么既是停止 |
https://blog.csdn.net/fuxuemingzhu/article/details/72465759 |
723. Repeated Substring Pattern |
Easy |
判断每个子串重复多次能不能组成原来的串即可 |
https://blog.csdn.net/fuxuemingzhu/article/details/54564801 |
724. Maximize Distance to Closest Person |
Easy |
从前向后以及从后向前遍历两次,取最近距离 |
https://blog.csdn.net/fuxuemingzhu/article/details/80643250 |
725. Count and Say |
Easy |
统计字符连续出现的次数,并说出来,需要注意最后的一个字符也要添加上去 |
https://blog.csdn.net/fuxuemingzhu/article/details/71618640 |
726. Remove Duplicates from Sorted Array II |
Easy |
快指针移动判断和慢指针是否相等,如果不等就换到前面来 |
https://blog.csdn.net/fuxuemingzhu/article/details/82829709 |
727. Maximum Average Subarray I |
Easy |
一定注意是长度为k的滑动窗口,注意下标 |
https://blog.csdn.net/fuxuemingzhu/article/details/79248629 |
728. Find Mode in Binary Search Tree |
Easy |
如果使用附加空间,可以使用字典保存次数;否则需要遍历两次,判断出现次数。 |
https://blog.csdn.net/fuxuemingzhu/article/details/71124600 |
729. Guess Number Higher or Lower |
Easy |
使用二分查找 |
https://blog.csdn.net/fuxuemingzhu/article/details/71516105 |
730. Network Delay Time |
Easy |
dijkstra算法 |
https://leetcode.com/problems/network-delay-time/description/ |
731. Quad Tree Intersection |
Easy |
递归构造 |
https://blog.csdn.net/fuxuemingzhu/article/details/82356008 |
732. Factorial Trailing Zeroes |
Easy |
数有多少个5就行了 |
https://blog.csdn.net/fuxuemingzhu/article/details/51347044 |
733. Arranging Coins |
Easy |
二分查找满足条件的层数即可 |
https://blog.csdn.net/fuxuemingzhu/article/details/71330733 |
734. Implement Stack using Queues |
Easy |
使用一个队列就能实现栈,每次Push的时候,把队列里的所有元素弹出再放进来就好了。 |
https://blog.csdn.net/fuxuemingzhu/article/details/72598111 |
735. Add Binary |
Easy |
使用进位进行模拟 |
ddhttps://blog.csdn.net/fuxuemingzhu/article/details/77341154v |
736. Number of Segments in a String |
Easy |
string.split()默认就是按照多个空格分割 |
https://blog.csdn.net/fuxuemingzhu/article/details/71194298 |
737. Path Sum |
Easy |
递归和迭代都能满足 |
https://blog.csdn.net/fuxuemingzhu/article/details/71715810 |
738. Isomorphic Strings |
Easy |
分别看s到t的映射和t到s的映射是不是一一映射的 |
https://blog.csdn.net/fuxuemingzhu/article/details/72127108 |
739. String Compression |
Easy |
使用Pos变量维护应该放到哪个位置,然后一次遍历统计次数就好了 |
https://blog.csdn.net/fuxuemingzhu/article/details/79183289 |
740. Range Sum Query - Immutable |
Easy |
保存每个位置的累积和 |
https://blog.csdn.net/fuxuemingzhu/article/details/79253036 |
741. Find All Anagrams in a String |
Easy |
滑动窗口,保存等长的子字符串中包含的字符数是否和另外一个相等 |
https://blog.csdn.net/fuxuemingzhu/article/details/79184109 |
742. Valid Parentheses |
Easy |
使用栈判断括号是否合法 |
https://blog.csdn.net/fuxuemingzhu/article/details/72366868 |
743. Magic Squares In Grid |
Easy |
暴力判断每个9*9的格子是不是满足题意的河图 |
https://blog.csdn.net/fuxuemingzhu/article/details/80473253 |
744. Linked List Cycle |
Easy |
走两步走一步,看是否重合 |
https://blog.csdn.net/fuxuemingzhu/article/details/51297249 |
745. Remove Linked List Elements |
Easy |
递归解法不好想,但是代码很简单 |
https://blog.csdn.net/fuxuemingzhu/article/details/77340945 |
746. Palindrome Linked List |
Easy |
利用一个数组保存所有的数字,然后判断数组是不是回文的。 |
https://blog.csdn.net/fuxuemingzhu/article/details/72597942 |
747. Minimum Depth of Binary Tree |
Easy |
DFS/BFS,其实DFS更难 |
https://blog.csdn.net/fuxuemingzhu/article/details/48519035 |
748. Word Pattern |
Easy |
一一映射 |
https://blog.csdn.net/fuxuemingzhu/article/details/72528424 |
749. Min Stack |
Easy |
使用辅助栈保存最小值 |
https://blog.csdn.net/fuxuemingzhu/article/details/79253237 |
750. Contains Duplicate II |
Easy |
使用字典保存出现的位置,当新的元素到来的时候,更新字典 |
https://blog.csdn.net/fuxuemingzhu/article/details/77387169 |
751. Valid Mountain Array |
Easy |
两个while就可以了 |
https://blog.csdn.net/fuxuemingzhu/article/details/84206380 |
752. Merge Sorted Array |
Easy |
从后向前进行遍历,每次找到大的往后移动 |
https://blog.csdn.net/fuxuemingzhu/article/details/77444695 |
753. X of a Kind in a Deck of Cards |
Easy |
需要进行一个遍历,找到是否存在这个分组大小 |
https://blog.csdn.net/fuxuemingzhu/article/details/82914279 |
754. Valid Palindrome II |
Easy |
需要用到双指针,先找到第一个不相等的位置,然后去除左边或者右边,判断是否是回文 |
https://blog.csdn.net/fuxuemingzhu/article/details/79252779 |
755. Longest Univalue Path |
Easy |
定义的DFS是对过root的单臂进行循环,但是更新的结果是双臂,有点意思 |
https://blog.csdn.net/fuxuemingzhu/article/details/79248926 |
756. Longest Common Prefix |
Easy |
遍历最短的子串的每一位,看所有字符串在这一位上是不是相等的 |
https://blog.csdn.net/fuxuemingzhu/article/details/77561186 |
757. Repeated String Match |
Easy |
重复NB/NA + 3次,看b是不是在a里 |
https://blog.csdn.net/fuxuemingzhu/article/details/79574835 |
122.Best Time to Buy and Sell Stock II |
Easy |
只要每天的比前面一天高,那么就买上并且卖掉即可 |
https://blog.csdn.net/fuxuemingzhu/article/details/70258549 |
758. Implement strStr() |
Easy |
循环加切片 |
https://blog.csdn.net/fuxuemingzhu/article/details/79254558 |
759. Heaters |
Easy |
找出最临近的距离 |
https://blog.csdn.net/fuxuemingzhu/article/details/79254295 |
760. Reach a Number |
Easy |
数学题,非常不喜欢 |
https://blog.csdn.net/fuxuemingzhu/article/details/84556932 |
761. Nth Digit |
Easy |
数学计算第多少位 |
https://blog.csdn.net/fuxuemingzhu/article/details/84559975 |
762. Sqrt(x) |
Easy |
二分查找或者牛顿法 |
https://blog.csdn.net/fuxuemingzhu/article/details/79254648 |
763. Shortest Unsorted Continuous Subarray |
Easy |
先排序,然后比较不等的位置 |
https://blog.csdn.net/fuxuemingzhu/article/details/79254454 |
764. Reverse Bits |
Easy |
翻转二进制再转成整数 |
https://blog.csdn.net/fuxuemingzhu/article/details/79254344 |
765. Valid Palindrome |
Easy |
过滤掉不是字母的字符,然后判断是不是回文即可 |
https://blog.csdn.net/fuxuemingzhu/article/details/79252936 |
766. Walking Robot Simulation |
Easy |
模拟整个过程即可 |
https://blog.csdn.net/fuxuemingzhu/article/details/82356556 |
767. K-diff Pairs in an Array |
Easy |
找绝对值出现等于k的次数,需要对k进行判断 |
https://blog.csdn.net/fuxuemingzhu/article/details/79255633 |
768. Excel Sheet Column Title |
Easy |
需要对26取余,并且做个判断,因为0\26对26取余的结果是一样的 |
https://blog.csdn.net/fuxuemingzhu/article/details/51286857 |
769. Rotate Array |
Easy |
可以使用额外数组,也可使用递归原地翻转 |
https://blog.csdn.net/fuxuemingzhu/article/details/79258753 |
770. Non-decreasing Array |
Easy |
找到变小的位置,然后和再前面的数字进行判断,看是应该修改当前的还是前面的 |
https://blog.csdn.net/fuxuemingzhu/article/details/79264475 |
771. Design Linked List |
Easy |
自己实现链表,挺复杂的。可以使用list进行模拟,方便很多。 |
https://blog.csdn.net/fuxuemingzhu/article/details/81026066 |
772. Range Sum of BST |
Medium |
需要根据根节点的值进行判断,邮编和左边需不需要继续寻找 |
https://blog.csdn.net/fuxuemingzhu/article/details/83961263 |
773. Max Increase to Keep City Skyline |
Medium |
分别找出行和咧的最大值,把每个位置增长到行列最大值的最小值 |
https://blog.csdn.net/fuxuemingzhu/article/details/79820383 |
774. Encode and Decode TinyURL |
Medium |
使用字典完成映射 |
https://blog.csdn.net/fuxuemingzhu |
775. Maximum Binary Tree |
Medium |
找到最大值,然后数组切片 |
https://blog.csdn.net/fuxuemingzhu/article/details/79265180 |
776. Insert into a Binary Search Tree |
Medium |
递归解法,直接对当前节点进行操作! |
https://blog.csdn.net/fuxuemingzhu/article/details/82385503 |
777. Find and Replace Pattern |
Medium |
判断是不是一一映射 |
https://blog.csdn.net/fuxuemingzhu/article/details/82014687 |
778. Minimum Add to Make Parentheses Valid |
Medium |
使用一个栈 |
https://blog.csdn.net/fuxuemingzhu/article/details/83045871 |
779. All Paths From Source to Target |
Medium |
回溯法找路径 |
https://blog.csdn.net/fuxuemingzhu/article/details/79624149 |
780. Score After Flipping Matrix |
Medium |
把行进行翻转,按列统计1的个数即可 |
https://blog.csdn.net/fuxuemingzhu/article/details/81118328 |
781. All Possible Full Binary Trees |
Medium |
使用两种循环遍历可能构成的左子树和右子树,每次构建新的root |
https://blog.csdn.net/fuxuemingzhu/article/details/82084204 |
782. Partition Labels |
Medium |
使用字典保存每个字符最后出现的位置,如果一个区间内字符的最后位置的都在一起,那么就添加到结果里 |
https://blog.csdn.net/fuxuemingzhu/article/details/79265829 |
783. Battleships in a Board |
Medium |
直接数有多少小岛就行,判断小岛可以使用它的最左上角元素即可 |
https://blog.csdn.net/fuxuemingzhu/article/details/79403172 |
784. Complex Number Multiplication |
Medium |
复数运算,重点是分割字符串 |
https://blog.csdn.net/fuxuemingzhu/article/details/79266080 |
785. Counting Bits |
Medium |
i的二进制1个数等于i/2的二进制个数+i%2 |
https://blog.csdn.net/fuxuemingzhu/article/details/70806676 |
786. Spiral Matrix III |
Medium |
保留循环更新步数,很恶心 |
https://blog.csdn.net/fuxuemingzhu/article/details/82389223 |
787. Custom Sort String |
Medium |
统计次数,拼接成字符串 |
https://blog.csdn.net/fuxuemingzhu/article/details/79378688 |
788. Find All Duplicates in an Array |
Medium |
原地变成负数,如果已经是负数,那么说明出现了两次。 |
https://blog.csdn.net/fuxuemingzhu/article/details/79275549 |
789. Design Twitter |
Medium |
使用优先级队列弹出最新的内容 |
https://blog.csdn.net/fuxuemingzhu/article/details/82155420 |
790. Keys and Rooms |
Medium |
可以使用DFS和BFS解决 |
https://blog.csdn.net/fuxuemingzhu/article/details/80476862 |
791. Queue Reconstruction by Height |
Medium |
先插入长得高的他们不会影响别人,然后在对应位置插入次高的 |
https://blog.csdn.net/fuxuemingzhu/article/details/68486884 |
792. Find Bottom Left Tree Value |
Medium |
层次遍历,找出最后一层的第一个节点即可 |
https://blog.csdn.net/fuxuemingzhu/article/details/70161829 |
793. Daily Temperatures |
Medium |
使用一个栈,保存每个元素,如果后面的元素比较大,那么就已知出栈操作 |
https://blog.csdn.net/fuxuemingzhu/article/details/79285081 |
794. Validate Stack Sequences |
Medium |
使用栈进行模拟,无论如何都把当前的元素弹出,然后和弹出的元素进行比较,相等的话一直弹出 |
https://blog.csdn.net/fuxuemingzhu/article/details/84495797 |
795. Find Largest Value in Each Tree Row |
Medium |
遍历每一层,找出最大值即可。 |
https://blog.csdn.net/fuxuemingzhu/article/details/70183314 |
796. Single Element in a Sorted Array |
Medium |
可以使用很风骚的二分查找k, |
https://blog.csdn.net/fuxuemingzhu/article/details/79275636 |
797. Construct Binary Tree from Preorder and Postorder Traversal |
Medium |
找到后序的倒数第二个元素就是右子树的根节点 |
https://blog.csdn.net/fuxuemingzhu/article/details/82391321 |
798. Single Number III |
Medium |
使用异或或者字典解决 |
https://blog.csdn.net/fuxuemingzhu/article/details/79434100 |
799. Optimal Division |
Medium |
这个题非常tricky,没意思 |
https://blog.csdn.net/fuxuemingzhu/article/details/79403723 |
800. Palindromic Substrings |
Medium |
判断回文,需要判断去掉两头字符之后是否仍然是回文,动态规划 |
https://blog.csdn.net/fuxuemingzhu/article/details/79433960 |
801. Max Area of Island |
Medium |
找到岛的数量,这个题可以使用BFS或者DFS的方法 |
https://blog.csdn.net/fuxuemingzhu/article/details/79182435 |
802. Score of Parentheses |
Medium |
可以使用栈和递归,这个题很巧妙,是个不错的题目 |
https://blog.csdn.net/fuxuemingzhu/article/details/84956643 |
803. Complete Binary Tree Inserter |
Medium |
使用数组保存每个节点的指针,因为是完全二叉树,所以节点位置除以2就得到了它的父亲节点 |
https://blog.csdn.net/fuxuemingzhu/article/details/82958284 |
804. Sort Characters By Frequency |
Medium |
根据出现次数排序,然后构建新的字符串即可 |
https://blog.csdn.net/fuxuemingzhu/article/details/79437548 |
805. Escape The Ghosts |
Medium |
找出是否存在更小的曼哈顿距离 |
https://blog.csdn.net/fuxuemingzhu/article/details/80480462 |
806. Binary Tree Inorder Traversal |
Medium |
中序遍历本身很简单,但是这个递归的写法不好想 |
https://blog.csdn.net/fuxuemingzhu/article/details/79294461 |
807. Smallest Subtree with all the Deepest Nodes |
Medium |
定义递归函数:返回<最大深度,最大深度对应的节点> |
https://blog.csdn.net/fuxuemingzhu/article/details/82432130 |
808. Most Frequent Subtree Sum |
Medium |
遍历求和,字典统计出现次数最多的所有元素 |
http://www.cnblogs.com/grandyang/p/6481682.html |
809. Beautiful Arrangement |
Medium |
经典回溯法,要背会 |
https://blog.csdn.net/fuxuemingzhu/article/details/79431941 |
810. Product of Array Except Self |
Medium |
使用两次遍历,分别从左边和右边向中间靠拢 |
https://blog.csdn.net/fuxuemingzhu/article/details/79325534 |
811. Minimum ASCII Delete Sum for Two Strings |
Medium |
和LCS很接近的DP题目 |
https://blog.csdn.net/fuxuemingzhu/article/details/79822689 |
812. Linked List Components |
Medium |
判断当前节点在set中,但是下一个节点不在即可 |
https://blog.csdn.net/fuxuemingzhu/article/details/80479431 |
813. Top K Frequent Elements |
Medium |
使用字典统计次数,使用优先级队列实现排序 |
https://blog.csdn.net/fuxuemingzhu/article/details/79294073 |
814. Minimum Moves to Equal Array Elements II |
Medium |
找出中位数,然后求所有数字到中位数的距离和 |
https://blog.csdn.net/fuxuemingzhu/article/details/79437926 |
815. Permutations |
Medium |
经典回溯法 |
https://blog.csdn.net/fuxuemingzhu/article/details/79363903 |
816. Teemo Attacking |
Medium |
计算每次中毒的开始和结束时间 |
https://blog.csdn.net/fuxuemingzhu/article/details/79438658 |
817. Generate Parentheses |
Medium |
经典回溯法 |
https://blog.csdn.net/fuxuemingzhu/article/details/79362373 |
818. Minesweeper |
Medium |
扫雷游戏,使用DFS |
https://blog.csdn.net/fuxuemingzhu/article/details/79462285 |
819. Beautiful Arrangement II |
Medium |
每次把后面最大数字放到前面来就能增加一种新的差值 |
https://blog.csdn.net/fuxuemingzhu/article/details/79437401 |
820. Map Sum Pairs |
Medium |
前缀树的题目,可以背一背 |
https://blog.csdn.net/fuxuemingzhu/article/details/79436619 |
821. Friend Circles |
Medium |
并查集的题目 |
https://blog.csdn.net/fuxuemingzhu/article/details/70258103 |
822. Array Nesting |
Medium |
一直遍历就好了,使用一个visited数组,但不是回溯。 |
https://blog.csdn.net/fuxuemingzhu/article/details/79460546 |
823. Most Stones Removed with Same Row or Column |
Medium |
需要使用并查集,非常考验抽象能力 |
https://blog.csdn.net/fuxuemingzhu/article/details/84500642 |
824. Mirror Reflection |
Medium |
镜像反射,需要找规律,分偶数和奇数进行讨论 |
https://blog.csdn.net/fuxuemingzhu/article/details/82432579 |
825. Implement Magic Dictionary |
Medium |
找到存不存在汉明间距是1 |
https://blog.csdn.net/fuxuemingzhu/article/details/79447934 |
826. Rabbits in Forest |
Medium |
对兔子出现次数进行统计,然后求一个公式。 |
https://blog.csdn.net/fuxuemingzhu/article/details/79457764 |
827. Max Chunks To Make Sorted |
Medium |
从左到右遍历一次,时刻保持当前的最大值,如果当前最大值等于索引,那么chunck+1. |
https://blog.csdn.net/fuxuemingzhu/article/details/80482014 |
828. Print Binary Tree |
Medium |
先把二叉树构造出来,然后使用类似二分查找左右分治的方法。 |
https://blog.csdn.net/fuxuemingzhu/article/details/79439026 |
829. Implement Trie (Prefix Tree) |
Medium |
构造字典树,是个好题,需要背会 |
https://blog.csdn.net/fuxuemingzhu/article/details/79388432 |
830. Replace Words |
Medium |
使用字典树或者拉链法求解 |
https://blog.csdn.net/fuxuemingzhu/article/details/79391682 |
831. Maximum XOR of Two Numbers in an Array |
Medium |
暴力求解会超时,需要使用异或的性质从最高位开始遍历。或者使用字典树。 |
https://blog.csdn.net/fuxuemingzhu/article/details/79473171 |
832. Combination Sum |
Medium |
回溯法,遍历开始的地方不变,要跟踪target |
https://blog.csdn.net/fuxuemingzhu/article/details/79322462 |
833. Combination Sum II |
Medium |
经典的回溯法,这个题需要背会 |
https://blog.csdn.net/fuxuemingzhu/article/details/79343638 |
834. Combination Sum III |
Medium |
也是经典回溯法,需要注意的是不重复,所以递归开始的地方要+1 |
https://blog.csdn.net/fuxuemingzhu/article/details/79343681 |
835. Combination Sum IV |
Medium |
这个题需要使用动态规划求次数了,并不用回溯法。类似于爬楼梯 |
https://blog.csdn.net/fuxuemingzhu/article/details/79343825 |
836. Subsets |
Medium |
使用回溯法进行搜索,需要注意的是要跟踪现在的位置,不能向回走 |
https://blog.csdn.net/fuxuemingzhu/article/details/79359540 |
837. Count Numbers with Unique Digits |
Medium |
这个题是找规律+动态规划,要计算1位数字、2位数字…n位数字每位数字都不重复的情况有多少个 |
https://blog.csdn.net/fuxuemingzhu/article/details/80552049 |
838. Combinations |
Medium |
这个组合问题需要跟踪现在的位置防止向后走,还要跟踪在剩余的数字里面取多少个 |
https://blog.csdn.net/fuxuemingzhu/article/details/80552049 |
839. Gray Code |
Medium |
格雷码是把比自己小一位的格雷码正向一遍,然后以1开头+小一位的格雷码反向一遍,是个递归过程 |
https://blog.csdn.net/fuxuemingzhu/article/details/80664204 |
840. Subsets II |
Medium |
这个求子集的时候要屏蔽相同的起始元素,在for循环里进行判断 |
https://blog.csdn.net/fuxuemingzhu/article/details/79785548 |
841. Letter Combinations of a Phone Number |
Medium |
这个是个排列问题,先把当前位置的所有字符一次排好,然后再排列后面的字符串 |
https://blog.csdn.net/fuxuemingzhu/article/details/79363119 |
842. Palindrome Partitioning |
Medium |
同样的回溯法,如果定义新函数没有太多难度,如果使用题目给定的函数进行递归需要额外判断终止条件 |
https://blog.csdn.net/fuxuemingzhu/article/details/79574462 |
843. Permutations II |
Medium |
如果当前数字和前面的数字相等,并且前面的数字没有访问过,那么就不能搜索 |
https://blog.csdn.net/fuxuemingzhu/article/details/79513261 |
844. Restore IP Addresses |
Medium |
回溯法,需要考虑ip的各种过滤条件,比如255和0开头的数字不合法 |
https://blog.csdn.net/fuxuemingzhu/article/details/80657420 |
845. Split Array into Fibonacci Sequence |
Medium |
回溯,需要注意不能超过int,和addative numbers很像 |
https://blog.csdn.net/fuxuemingzhu/article/details/80662840 |
846. Permutation Sequence |
Medium |
需要找规律,每一位等于剩余数字/剩余位数的全排列 |
https://blog.csdn.net/fuxuemingzhu/article/details/80658810 |
847. Word Search |
Medium |
也是经典回溯法,需要保存是否已经访问过了某个位置,总体代码很常见 |
https://blog.csdn.net/fuxuemingzhu/article/details/79386066 |
848. Add and Search Word - Data structure design |
Medium |
Trie加上递归,本身不难,注意遍历所有子节点然后递归的操作 |
https://blog.csdn.net/fuxuemingzhu/article/details/79390052 |
849. N-Queens II |
Medium |
回溯法去解决。使用一维的数组保存每行放在第多少列,进行有效棋盘判断的时候,需要判断同列或者斜率绝对值1 |
https://blog.csdn.net/fuxuemingzhu/article/details/79517109 |
850. Shopping Offers |
Medium |
使用回溯法进行求解,套餐和单独点都进行尝试,这个题经常考! |
https://blog.csdn.net/fuxuemingzhu/article/details/82504050 |
851. Binary Tree Preorder Traversal |
Medium |
这个先序遍历迭代解法使用的是栈,有点违反直觉,建议仔细思考思考 |
https://blog.csdn.net/fuxuemingzhu/article/details/72575422 |
852. Asteroid Collision |
Medium |
栈里保留着向右移动的小行星,如果当前的行星是向左的,向栈里面判断自身是否销毁 |
https://blog.csdn.net/fuxuemingzhu/article/details/81079015 |
853. Next Greater Element II |
Medium |
单调递减栈,这个题难点在于循环数组,容易分析出把数组过两遍即可,需要求余 |
https://blog.csdn.net/fuxuemingzhu/article/details/79463006 |
854. Image Overlap |
Medium |
正方形重合,使用字典保存两两之间向量的差,求最大的移动向量出现的次数 |
https://blog.csdn.net/fuxuemingzhu/article/details/82597238 |
855. Minimum Path Sum |
Medium |
最小路径和,简单的动态规划,注意初始状态 |
https://blog.csdn.net/fuxuemingzhu/article/details/82620422 |
856. Unique Paths |
Medium |
简单的动态规划,给周围包上一圈全0的数字,方便状态转移 |
https://blog.csdn.net/fuxuemingzhu/article/details/79337352 |
857. Unique Paths II |
Medium |
也是动态规划,和上面的区别在于有障碍物,直接设置障碍物处的状态是0 |
https://blog.csdn.net/fuxuemingzhu/article/details/83154114 |
858. Rotate Image |
Medium |
先上下翻转,再沿着主对角线翻转即可完成旋转操作 |
https://blog.csdn.net/fuxuemingzhu/article/details/79451733 |
859. Target Sum |
Medium |
使用动态规划,dp[i][j]表示到第i个位置位置构成和为j的组合有多少种 |
https://blog.csdn.net/fuxuemingzhu/article/details/80484450 |
860. Unique Binary Search Trees |
Medium |
记忆化递归,动态规划,卡特兰数等等,方法很多 |
https://blog.csdn.net/fuxuemingzhu/article/details/79367789 |
861. Decode String |
Medium |
字符串解码,需要用到栈保存已经有的字符串和当前的数字,很经典的题目 |
https://blog.csdn.net/fuxuemingzhu/article/details/79332894 |
862. Group Anagrams |
Medium |
对字符串进行排序,排序之后相等的字符串说明包含的字符相等 |
https://blog.csdn.net/fuxuemingzhu/article/details/69831375 |
863. Task Scheduler |
Medium |
任务调度题目,很容易推出公式,但是切记整个时间最少满足任务个数 |
https://blog.csdn.net/fuxuemingzhu/article/details/81947087 |
864. Best Time to Buy and Sell Stock with Cooldown |
Medium |
经典动态规划的题目,这个题需要定义两个数组:今天有股票的情况下的收益和今天没有股票情况下的收益,然后状态转移就简单了 |
https://blog.csdn.net/fuxuemingzhu/article/details/82656899 |
865. Best Time to Buy and Sell Stock with Transaction Fee |
Medium |
动态规划,做法和上面非常类似,每次计算收益的时候需要减去手续费 |
https://blog.csdn.net/fuxuemingzhu/article/details/79888528 |
866. Flatten Binary Tree to Linked List |
Medium |
如果用递归的话一定明白递归函数是把一个二叉树弄平形成链表,然后找到链表尾部,把链表拼接 |
https://blog.csdn.net/fuxuemingzhu/article/details/70241424 |
867. Longest Increasing Subsequence |
Medium |
LIS问题,是dp最经典的题目之一,需要从每个位置向前遍历以更新dp |
https://blog.csdn.net/fuxuemingzhu/article/details/79820919 |
868. Search a 2D Matrix II |
Medium |
从矩阵的左下或者右上开始遍历,很简单 |
https://blog.csdn.net/fuxuemingzhu/article/details/79459314 |
869. Search a 2D Matrix |
Medium |
在二维数组中进行搜索,可以使用矩阵左下和右上角的查询方法,也可以直接遍历每一个位置。 |
https://blog.csdn.net/fuxuemingzhu/article/details/79459200 |
870. Perfect Squares |
Medium |
动态规划,一个数字能由多少个整数平方和构成等于满足更小数字+平方数 的状态+1。 |
https://blog.csdn.net/fuxuemingzhu/article/details/51284292 |
871. Partition Equal Subset Sum |
Medium |
把数字的累计和当做状态,当前的状态等于前面的数字累积和-当前数值的状态。 |
https://blog.csdn.net/fuxuemingzhu/article/details/79787425 |
872. Contiguous Array |
Medium |
求累积和,然后判断在这个位置前面,这个累计和是不是出现过 |
https://blog.csdn.net/fuxuemingzhu/article/details/82667054 |
873. Merge Intervals |
Medium |
使用start和end两个变量表示区间,当区间不再重叠的时候把上面区间放入结果中,重置start和end |
https://blog.csdn.net/fuxuemingzhu/article/details/69078468 |
874. Course Schedule |
Medium |
拓扑排序,每次弹出入度为0的节点,并把以他为入度的所有节点的入度-1 |
https://blog.csdn.net/fuxuemingzhu/article/details/82951771 |
875. Construct Binary Tree from Preorder and Inorder Traversal |
Medium |
前序遍历的首节点就是根节点,在中序中的位置坐标是左子树,右边是右子树 |
https://blog.csdn.net/fuxuemingzhu/article/details/80775173 |
876. Lowest Common Ancestor of a Binary Tree |
Medium |
这个递归调用需要注意如果查找到任何一个节点都算是找到了最低公共祖先 |
https://blog.csdn.net/fuxuemingzhu/article/details/80778001 |
877. Word Break |
Medium |
动态规划,每个位置的状态由前面的某个状态+一个条件得到,搜索是两重循环 |
https://blog.csdn.net/fuxuemingzhu/article/details/79368360 |
878. Minimum Size Subarray Sum |
Medium |
虫取法,找到最小长度的满足区间 |
https://blog.csdn.net/fuxuemingzhu/article/details/83063096 |
879. Sort List |
Medium |
对于list的merge sort。 |
https://blog.csdn.net/fuxuemingzhu/article/details/79630742 |
880. Find First and Last Position of Element in Sorted Array |
Medium |
自己实现lower_bound和upper_bound函数,使用二分 |
https://blog.csdn.net/fuxuemingzhu/article/details/83273084 |
881. Search in Rotated Sorted Array |
Medium |
对二分的进一步理解:判断下一步查找的范围到底在mid左边还是右边 |
https://blog.csdn.net/fuxuemingzhu/article/details/79534213 |
882. Maximal Square |
Medium |
这个题使用dp,某位置的最大正方形边长等于左边、上边、左上边三个位置最小的边长+1 |
https://blog.csdn.net/fuxuemingzhu/article/details/82992233 |
883. Jump Game |
Medium |
贪心算法,保存每一步都选择跳的最远的地方,如果这个位置不能到达直接返回false. |
https://blog.csdn.net/fuxuemingzhu/article/details/83504437 |
884. Find the Duplicate Number |
Medium |
寻找重复的数字,相当于链表中的环,也可以使用二分查找 |
https://blog.csdn.net/fuxuemingzhu/article/details/79530847 |
885. Linked List Cycle II |
Medium |
找出链表环的入口,可以使用双指针,也可以使用set保存已经遍历过的路径 |
https://blog.csdn.net/fuxuemingzhu/article/details/79530638#set_134 |
886. Add Two Numbers |
Medium |
两个链表的加法,只要有一个链表不空或者进位存在就添加新的节点 |
https://blog.csdn.net/fuxuemingzhu/article/details/79379626 |
887. Next Permutation |
Medium |
找到后面的第一个不降序数字,与第一个比它大的位置进行交换,然后把后面部分翻转即可 |
https://blog.csdn.net/fuxuemingzhu/article/details/82113409 |
888. Word Search |
Medium |
标准的回溯法,需要向周围进行搜索,同时保存已经遍历了的位置不再访问 |
https://blog.csdn.net/fuxuemingzhu/article/details/79386066 |
889. Coin Change |
Medium |
动态规划,定义dp数组是能够成的amount的最少硬币数,遍历硬币更新每个amount |
https://blog.csdn.net/fuxuemingzhu/article/details/83592442 |
890. Maximum Product Subarray |
Medium |
求连续数组最大积,需要保存每个位置的最大、最小积,每个位置都去维护这两个变量 |
https://blog.csdn.net/fuxuemingzhu/article/details/83211451 |
891. Longest Palindromic Substring |
Medium |
字符串的简单动态规划,也可以直接暴力求解 |
https://blog.csdn.net/fuxuemingzhu/article/details/79573621 |
892. Validate Binary Search Tree |
Medium |
递归函数中维护每个节点的取值上下限即可。或者有序的中序遍历是个BST |
https://blog.csdn.net/fuxuemingzhu/article/details/70209865 |
893. Longest Substring Without Repeating Characters |
Medium |
虫取法+set找到每个不含重复元素的子串,保存最长子串 |
https://blog.csdn.net/fuxuemingzhu/article/details/82022530 |
894. Implement Rand10() Using Rand7() |
Medium |
需要先构造出rand40,然后mod10即可得到rand10. |
https://blog.csdn.net/fuxuemingzhu/article/details/81809478 |
895. Integer Break |
Medium |
任意>=2的整数都可以拆解成2x+3y,当y尽可能大的时候target = 2x+3y的结果最大 |
https://blog.csdn.net/fuxuemingzhu/article/details/80486238 |
896. Redundant Connection |
Medium |
并查集的题目,这种题目是个模板,应该背会DSU的代码 |
https://blog.csdn.net/fuxuemingzhu/article/details/80487064 |
897. Integer to Roman |
Medium |
整数变成罗马数字,把整数进行拆解即可,在拆解的过程中拼接每个数字对应的字符 |
https://blog.csdn.net/fuxuemingzhu/article/details/48210399 |
898. Kth Smallest Element in a BST |
Medium |
递归解法需要使用全局变量保存已经遍历了多少个了,到达k个时直接停止并返回即可。 |
https://blog.csdn.net/fuxuemingzhu/article/details/69947495 |
899. Bulb Switcher II |
Medium |
智力题,被踩了很多次,没仔细做 |
https://blog.csdn.net/fuxuemingzhu/article/details/79451356 |
900. Reordered Power of 2 |
Medium |
思路要灵活一点,直接统计数字出现的次数是否相等即可,不必真的重新排序 |
https://blog.csdn.net/fuxuemingzhu/article/details/82468653 |
901. Shuffle an Array |
Medium |
Fisher–Yates 洗牌算法:依次遍历列表中的每一位,并将这一位与其后面的随机一位交换顺序。 |
https://blog.csdn.net/fuxuemingzhu/article/details/79391342 |
902. Add Two Numbers II |
Medium |
使用额外空间保存两个列表的值元素,然后再模拟加法 |
https://blog.csdn.net/fuxuemingzhu/article/details/79380457 |
903. Minimum Area Rectangle |
Medium |
对角线确定长方形,判断另外一条对角线上的两个点是不是存在即可 |
https://leetcode.com/problems/minimum-area-rectangle/ |
904. Different Ways to Add Parentheses |
Medium |
这是个递归求解的题目,如果遇到一个运算符就把左右两部分分别求出值,然后再做操作。左右部分分别求值求相当于给左右部分分别加上了括号 |
https://blog.csdn.net/fuxuemingzhu/article/details/79568487 |
905. Design Circular Deque |
Medium |
设计deque,最简单的方法是使用双向链表 |
https://blog.csdn.net/fuxuemingzhu/article/details/81027989 |
906. Random Pick Index |
Medium |
使用蓄水池抽样,每个数字被选择的概率是1/cnt,遍历结束即可 |
https://blog.csdn.net/fuxuemingzhu/article/details/79540576 |
907. Linked List Random Node |
Medium |
和上题一致,蓄水池抽样 |
https://blog.csdn.net/fuxuemingzhu/article/details/79488113 |
908. RLE Iterator |
Medium |
一个循环,判断当前位置和剩下的数字n之间的关系,看是否向后走即可 |
https://blog.csdn.net/fuxuemingzhu/article/details/82757347 |
909. Total Hamming Distance |
Medium |
统计int的32位中有多少个数字该位是1、多少个数字该位是0,结果是两者相乘 |
https://blog.csdn.net/fuxuemingzhu/article/details/79494653 |
910. Split Linked List in Parts |
Medium |
求出每一段的长度,然后定一个函数切链表即可 |
https://blog.csdn.net/fuxuemingzhu/article/details/79543931#_57 |
911. Hand of Straights |
Medium |
使用map保存每个数字的次数,然后向后遍历W-1个数字,判断是否都存在即可 |
https://blog.csdn.net/fuxuemingzhu/article/details/82530857 |
912. Copy List with Random Pointer |
Medium |
遍历两遍,第一遍构造的节点放到字典里,第二遍遍历再连接起来 |
https://blog.csdn.net/fuxuemingzhu/article/details/80787528 |
399. Evaluate Division |
Medium |
带权有向图的搜索问题 |
https://blog.csdn.net/fuxuemingzhu/article/details/82591165 |
636. Exclusive Time of Functions |
Medium |
计算机函数的调度问题,使用栈解决 |
https://blog.csdn.net/fuxuemingzhu/article/details/79537000 |
646. Maximum Length of Pair Chain |
Medium |
这个就是最多能看多少个电视节目的问题,使用的是贪心法,策略是优先选择结束时间早的项目 |
https://blog.csdn.net/fuxuemingzhu/article/details/79826524 |
328. Odd Even Linked List |
Medium |
先分别构建偶数位置的链表和奇数位置的链表,把对应位置的结果放到对应位置之后,再拼接即可 |
https://blog.csdn.net/fuxuemingzhu/article/details/79569396 |
638. Shopping Offers |
Medium |
DFS进行搜索,尝试每种套餐方案 |
https://blog.csdn.net/fuxuemingzhu/article/details/82504050 |
318. Maximum Product of Word Lengths |
Medium |
直接O(N^2)遍历即可 |
https://blog.csdn.net/fuxuemingzhu/article/details/80932597 |
173. Binary Search Tree Iterator |
Medium |
把每个节点的左孩子放到栈中,遍历栈中节点的时候需要把其右孩子的所有左孩子放到栈中 |
https://blog.csdn.net/fuxuemingzhu/article/details/79436947 |
337. House Robber III |
Medium |
递归查找每个节点可不可以用的情况下,最优结果是多少。可不可以用是由父亲节点用没用过决定的,所以递归函数有个变量保存父亲节点的状态。 |
https://blog.csdn.net/fuxuemingzhu/article/details/80779068 |
343. Integer Break |
Medium |
需要证明把一个数字拆成尽可能多的3和尽可能少的4的和的时候,总乘积最大 |
https://blog.csdn.net/fuxuemingzhu/article/details/80486238 |
875. Koko Eating Bananas |
Medium |
这个是一个变相的二分查找,需要根据当前的值判断查找后的移动 |
https://blog.csdn.net/fuxuemingzhu/article/details/82716042 |
901. Online Stock Span |
Medium |
需要使用一个单调递减栈保存每个数字的前面出现了多少小于等于该数字的数,后来的数字需要吞掉栈中比自己小的数字 |
https://blog.csdn.net/fuxuemingzhu/article/details/82781059 |