![](https://img-blog.csdnimg.cn/20201014180756916.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
算法练手
文章平均质量分 74
TheSnowBoy_2
知乎:https://www.zhihu.com/people/wang-kang-84-84/activities
展开
-
【精】ACM - 【ACM 基本输入输出格式】
本文章的目的本文章的主要目的在于说明在acm刷题过程中,应该注意哪些方面的格式上面的错误。题目描述春天是鲜花的季节,水仙花就是其中最迷人的代表,数学上有个水仙花数,他是这样定义的:“水仙花数”是指一个三位数,它的各位数字的立方和等于其本身,比如:153=1^3+5^3+3^3。 现在要求输出所有在m和n范围内的水仙花数。 输入描述:输入数据有多组,每组占原创 2017-08-08 19:19:36 · 907 阅读 · 0 评论 -
leetcode - 657. Judge Route Circle【向量思维 + 方向抵消(x,y)】
题目Initially, there is a Robot at position (0, 0). Given a sequence of its moves, judge if this robot makes a circle, which means it moves back to the original place.The move sequence is repres原创 2017-08-20 18:46:20 · 586 阅读 · 0 评论 -
【精】leetcode - 647. Palindromic Substrings【动态规划 + 回文 + 对称性】
题目Given a string, your task is to count how many palindromic substrings in this string.The substrings with different start indexes or end indexes are counted as different substrings even they co原创 2017-08-06 14:50:07 · 2679 阅读 · 0 评论 -
【精】leetcode - 441. Arranging Coins 【二分查找 + 整数的范围陷阱】
题目You have a total of n coins that you want to form in a staircase shape, where everyk-th row must have exactly k coins.Given n, find the total number of full staircase rows that can be form原创 2017-07-28 22:35:57 · 1376 阅读 · 0 评论 -
【神奇的技巧】leetcode - 661. Image Smoother【整数位信息使用 + 二维数组边界考虑 + 数组的巧妙使用】
题目1:661. Image SmootherGiven a 2D integer matrix M representing the gray scale of an image, you need to design a smoother to make the gray scale of each cell becomes the average gray scale (原创 2017-08-20 16:55:33 · 2151 阅读 · 0 评论 -
leetcode - 663. Equal Tree Partition
题目Given a binary tree with n nodes, your task is to check if it's possible to partition the tree to two trees which have the equal sum of values after removing exactly one edge on the original原创 2017-08-21 13:47:58 · 917 阅读 · 0 评论 -
【疑问】leetcode - 658. Find K Closest Elements【二分查找 + 双指针 + 找最近】
题目Given a sorted array, two integers k and x, find the k closest elements to x in the array. The result should also be sorted in ascending order. If there is a tie, the smaller elements are al原创 2017-08-20 19:39:02 · 1864 阅读 · 0 评论 -
编程题目索引
数学相关【京东】小球的距离【思路】该题目让你感受到数学中求极限在编程中的作用。(手动计算公式,然后在编程中代入相关的变量。【考察】数学功底 + 联系数学知识与计算机问题【阿里】面试OR笔试2——城堡问题 计算机几何,凸点的判断。直线的确定。(直线上点的判断)原创 2017-08-06 14:56:19 · 515 阅读 · 0 评论 -
leetcode - 234. Palindrome Linked List【判断回文链表 + 双指针 + O(1)空间复杂度】
题目Given a singly linked list, determine if it is a palindrome.Follow up:Could you do it in O(n) time and O(1) space?分析及解答解法1:(利用栈)class Solution { public boolean isPalindrome(Lis原创 2017-08-21 23:47:14 · 603 阅读 · 0 评论 -
leetcode - 662. Maximum Width of Binary Tree【广度优先遍历 + 层次计数】
题目Given a binary tree, write a function to get the maximum width of the given tree. The width of a tree is the maximum width among all levels. The binary tree has the same structure as a full bina原创 2017-08-20 16:57:05 · 3527 阅读 · 0 评论 -
leetcode - 572. Subtree of Another Tree 【树比较(结构、值)】
题目Given two non-empty binary trees s andt, check whether tree t has exactly the same structure and node values with a subtree ofs. A subtree of s is a tree consists of a node ins and all of原创 2017-08-05 09:52:59 · 422 阅读 · 0 评论 -
leetcode - 617. Merge Two Binary Trees【双树遍历 + null 模拟遍历 + 结点复用】
题目Given two binary trees and imagine that when you put one of them to cover the other, some nodes of the two trees are overlapped while the others are not.You need to merge them into a new bin原创 2017-08-05 09:45:18 · 483 阅读 · 0 评论 -
leetcode - 160. Intersection of Two Linked Lists【2个链表 + 长度对齐 + 栈】
题目Write a program to find the node at which the intersection of two singly linked lists begins.For example, the following two linked lists: A: a1 → a2 ↘原创 2017-08-08 21:28:25 · 421 阅读 · 0 评论 -
【启发】leetcode - 141. Linked List Cycle 【环判断 + 缩减 + 更改数据结构】
前言通过本题想说明,当给定你一个数据结构(比如说,链表的头指针,树的根)作为输入时,你在求解问题的时候,应不应该更改其结构,以及如何更改其结构。题目Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?原创 2017-08-08 22:00:27 · 429 阅读 · 0 评论 -
leetcode - 538. Convert BST to Greater Tree【遍历方式的选择 + 队列 + 巧用全局变量】
题目Given a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST is changed to the original key plus sum of all keys greater than the original key in BST.原创 2017-08-08 22:15:42 · 391 阅读 · 0 评论 -
144. Binary Tree Preorder Traversal 【先序遍历 + 栈模拟递归】
题目Given a binary tree, return the preorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [1,2,3].Note: Recursive solution i原创 2017-08-16 11:36:47 · 380 阅读 · 0 评论 -
【启发】94. Binary Tree Inorder Traversal(树的非递归遍历 + 栈模拟递归)
题目Given a binary tree, return the inorder traversal of its nodes' values.For example:Given binary tree [1,null,2,3], 1 \ 2 / 3return [1,3,2].Note: Recursive solution原创 2017-08-16 10:41:41 · 623 阅读 · 0 评论 -
【启发】leetcode - 145. Binary Tree Postorder Traversal【二叉树 + 后序遍历 + 非递归实现】
题目Given a binary tree, return the postorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [3,2,1].Note: Recursive solution原创 2017-08-16 14:11:24 · 524 阅读 · 0 评论 -
leetcod - 524. Longest Word in Dictionary through Deleting【字符串匹配 + 双指针 + Comparator + java高效函数】
题目Given a string and a string dictionary, find the longest string in the dictionary that can be formed by deleting some characters of the given string. If there are more than one possible result原创 2017-08-17 19:24:20 · 525 阅读 · 0 评论 -
leetcode - 637. Average of Levels in Binary Tree【广度优先遍历 + 辅助变量】
题目Given a non-empty binary tree, return the average value of the nodes on each level in the form of an array.Example 1:Input: 3 / \ 9 20 / \ 15 7Output: [3, 14.5, 11]Ex原创 2017-08-05 09:31:12 · 403 阅读 · 0 评论 -
【启发】求有环单链表中的环长、环起点、链表长【快 、 慢指针】
1.判断单链表是否有环 使用两个slow, fast指针从头开始扫描链表。指针slow 每次走1步,指针fast每次走2步。如果存在环,则指针slow、fast会相遇;如果不存在环,指针fast遇到NULL退出。 就是所谓的追击相遇问题: 2.求有环单链表的环长 在环上相遇后,记录第一次相遇点为Pos,之后指针slow继续每次走1步,fast每转载 2017-08-27 00:56:56 · 516 阅读 · 0 评论 -
情人节,用C++画一个心:)
文章出处:情人节,用C++画一个心情人节到啦,作为程序员开发者,应该送给男女朋友什么礼物呢?我们这次一起用C++语言画个心作为礼物吧!(被罚跪搓衣板儿什么的概不负责= =)在网上稍微查一查心形的曲线方程,会发现很多,最流行的曲线方程应该就是这个了:嗯,方程看着复杂,我们不管这是怎么推导出来的(我真的不会啊= =,不过我会一个更丑的心形曲线的推导过程,大家有兴趣的话有时间转载 2017-08-28 21:26:40 · 6042 阅读 · 0 评论 -
【剑指offer】正则匹配
链接:https://www.nowcoder.com/questionTerminal/45327ae22b7b413ea21df13ee7d6429c来源:牛客网题目请实现一个函数用来匹配包括'.'和'*'的正则表达式。模式中的字符'.'表示任意一个字符,而'*'表示它前面的字符可以出现任意次(包含0次)。 在本题中,匹配是指字符串的所有字符匹配整个模式。例如,字符串"aaa"与模转载 2017-08-29 11:51:03 · 396 阅读 · 0 评论 -
leetcode -- 691. Stickers to Spell Word【动态规划 + 位图使用】
题目We are given N different types of stickers. Each sticker has a lowercase English word on it.You would like to spell out the given target string by cutting individual letters from your co转载 2017-10-09 11:02:56 · 3493 阅读 · 0 评论 -
leetcode -- 15. 3Sum 【问题转化2sum + 避免重复计算的方法(规定次序)】
题目Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note: The solution set must not原创 2017-10-02 17:57:50 · 1177 阅读 · 0 评论 -
leetcode -- 14. Longest Common Prefix
题目Write a function to find the longest common prefix string amongst an array of strings.分析及解答class Solution { public String longestCommonPrefix(String[] strs) { if(strs ==原创 2017-10-02 18:12:03 · 399 阅读 · 0 评论 -
【精】leetcode - 650. 2 Keys Keyboard 【动态规划 + 质数 & 非质数 + 简洁表达】
题目Initially on a notepad only one character 'A' is present. You can perform two operations on this notepad for each step:Copy All: You can copy all the characters present on the notepad (par原创 2017-08-05 15:36:02 · 1806 阅读 · 0 评论 -
【leetcode-medium】Encode and Decode TinyURL 【对url进行编码】
题目TinyURL is a URL shortening service where you enter a URL such as https://leetcode.com/problems/design-tinyurl and it returns a short URL such as http://tinyurl.com/4e9iAk.Design the encode and ...原创 2018-08-11 11:56:31 · 442 阅读 · 0 评论 -
【leetcode-medium】Score After Flipping Matrix【寻找结果最优化的规则】
题目:We have a two dimensional matrix A where each value is 0 or 1.A move consists of choosing any row or column, and toggling each value in that row or column: changing all 0s to 1s, and all 1s to ...原创 2018-08-11 19:44:07 · 307 阅读 · 0 评论 -
【leetcode-medium】814. Binary Tree Pruning【修剪二叉樹】【自底向上反馈、修剪】
题目We are given the head node root of a binary tree, where additionally every node's value is either a 0 or a 1.Return the same tree where every subtree (of the given tree) not containing a 1 has b...原创 2018-08-11 20:11:40 · 368 阅读 · 0 评论 -
Top K Frequent Elements【出现次数最多的k个元素 + 数据结构使用 + 函数式编程】
题目Given a non-empty array of integers, return the k most frequent elements.Example 1:Input: nums = [1,1,1,2,2,3], k = 2Output: [1,2]Example 2:Input: nums = [1], k = 1Output: [1]Note:...翻译 2019-02-24 15:14:01 · 514 阅读 · 0 评论 -
leetcode -- 385. Mini Parser【简单解析器 + 编程语言的解析器 + 递归 + 解析的规则 + 结果的数据结构】
题目Given a nested list of integers represented as a string, implement a parser to deserialize it.Each element is either an integer, or a list -- whose elements may also be integers or other l原创 2017-10-17 22:57:42 · 1019 阅读 · 0 评论 -
今日头条笔试【编程题 + 分析过程发现数学规律 + 回溯法】
编程题题目1:(回溯法)【题目描述】给定一个矩阵,从某点出发,找到箱子,然后把箱子推到目的地。计算最少使用多少步。无法到达用-1表示。public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); String str = in.原创 2017-10-17 22:36:26 · 986 阅读 · 0 评论 -
【启发】leetcode -- 547. Friend Circles【并查集 + 集合标识更新的时机】
题目There are N students in a class. Some of them are friends, while some are not. Their friendship is transitive in nature. For example, if A is a direct friend of B, and B is a direct friend o原创 2017-10-08 11:00:15 · 763 阅读 · 0 评论 -
科大讯飞 - 站队冲突问题
说明:【贪心算法】有冲突,向前走一定让 L 赢; 向后走一定让 R 赢。【贪心算法】每遇到一个L, 将其前面的R全部清除。【注意】只有RL 才会导致冲突。(LR不会导致冲突)import java.util.Scanner;public class Main { public static void main(String[] args) { Scanner原创 2017-09-16 17:16:11 · 449 阅读 · 0 评论 -
leetcode - 303. Range Sum Query - Immutable 【动态规划 + 间接逼近目标 + 区间计算 +刻度 + 距离计算方式 】
题目Given an integer array nums, find the sum of the elements between indicesi and j (i ≤ j), inclusive.Example:Given nums = [-2, 0, 3, -5, 2, -1]sumRange(0, 2) -> 1sumRange(2, 5) -> -1s原创 2017-08-31 11:26:11 · 512 阅读 · 0 评论 -
【启发】leetcode - 121. Best Time to Buy and Sell Stock 【动态规划 + 连续区间问题 + 试探性购买】
题目Say you have an array for which the ith element is the price of a given stock on dayi.If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the st原创 2017-08-31 12:27:14 · 516 阅读 · 0 评论 -
leetcode - 646. Maximum Length of Pair Chain 【贪心 + 快排的应用+ 任务调度问题】
題目You are given n pairs of numbers. In every pair, the first number is always smaller than the second number.Now, we define a pair (c, d) can follow another pair(a, b) if and only if b . Chain原创 2017-09-01 10:15:15 · 461 阅读 · 0 评论 -
leetcode - 96. Unique Binary Search Trees【卡特兰数 + 整数处理注意】
题目Given n, how many structurally unique BST's (binary search trees) that store values 1...n?For example,Given n = 3, there are a total of 5 unique BST's. 1 3 3 2 1原创 2017-09-01 15:57:40 · 494 阅读 · 0 评论 -
今日头条编程题 - 珠子颜色【窗口滑动】
import java.util.ArrayList;import java.util.Scanner;public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); while (in.hasNextLine()) {原创 2017-09-11 14:17:10 · 782 阅读 · 0 评论