leetcode
不了痕
风景很美,常回头看看
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
二叉树相关算法题目总结
二叉树基础二叉树本身是一个每个节点最多包含左右两个节点的树。对于二叉树来讲,不像其他集合(List,Map)之类的有已经造好的轮子直接拿来用。所以多数场景下,遇到二叉树,需要我们自己来定义二叉树的数据结构。public class TreeNode { public int val; public TreeNode left; public TreeNode right; public TreeNode(int val) { this.val原创 2020-05-31 17:27:00 · 712 阅读 · 0 评论 -
【leetcode 77】Combinations 元素组合
题目Given two integersnandk, return all possible combinations ofknumbers out of 1 ...n.Example:Input:n = 4, k = 2Output:[ [2,4], [3,4], [2,3], [1,2], [1,3], [1,4],]解题思路...原创 2020-03-22 13:22:30 · 377 阅读 · 0 评论 -
【leetcode 122】Best Time to Buy and Sell Stock II 最佳买卖股票时间
题目Say you have an array for which theithelement is the price of a given stock on dayi.Design an algorithm to find the maximum profit. You may complete as many transactions as you like (i.e., b...原创 2020-03-05 21:44:25 · 274 阅读 · 0 评论 -
【leetcode 103】Binary Tree Zigzag Level Order Traversal 二叉树之字形层序遍历
题目ShareGiven a binary tree, return thezigzag level ordertraversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between).For example:Give...原创 2020-03-05 21:18:36 · 326 阅读 · 0 评论 -
【leetcode 102】Binary Tree Level Order Traversal 二叉树层序遍历
题目Given a binary tree, return thelevel ordertraversal of its nodes' values. (ie, from left to right, level by level).For example:Given binary tree[3,9,20,null,null,15,7], 3 / \ 9 ...原创 2020-03-05 21:13:26 · 317 阅读 · 0 评论 -
【leetcode 98】Validate Binary Search Tree 二叉搜索树
题目Given a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The left subtree of a node contains only nodes with keysless thanthe node's key....原创 2020-03-04 23:17:01 · 289 阅读 · 0 评论 -
【leetcode 100】Same Tree 相同树
题目Given two binary trees, write a function to check if they are the same or not.Two binary trees are considered the same if they are structurally identical and the nodes have the same value.Exa...原创 2020-03-04 23:11:49 · 308 阅读 · 0 评论 -
【leetcode 101】Symmetric Tree 对称数
题目Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree[1,2,2,3,4,4,3]is symmetric: 1 / \ 2 2 / \ / \3 4 4 ...原创 2020-03-04 23:05:26 · 233 阅读 · 0 评论 -
【leetcode 12】 Integer to Roman 数字转罗马数字
题目Roman numerals are represented by seven different symbols:I,V,X,L,C,DandM.Symbol ValueI 1V 5X 10L 50C 100D ...原创 2020-03-04 22:14:18 · 259 阅读 · 0 评论 -
(一)一个简单的取物游戏的算法
博主是一个java菜鸟,偶然间朋友推荐博主找leetcode.com上的算法从简单到难没事就写几个,所以博主决定每一到两天贴出一个自己写的算法code,因为是新手,代码一定显得拙劣,希望能和大神以及编程爱好者们相互交流,共同提高。以下是今天的算法和code:You are playing the following Nim Game with your friend: Ther原创 2016-03-27 10:43:41 · 1511 阅读 · 0 评论 -
(二)一个简单的加数算法
Given a non-negative integernum, repeatedly add all its digits until the result has only one digit.For example:Givennum = 38, the process is like:3 + 8 = 11,1 + 1 = 2. Since2has on原创 2016-03-29 15:28:49 · 570 阅读 · 0 评论 -
回溯法总结
概念回溯法是一种优选的搜索法,又称试探法。按选优条件向前搜索,已达到目标。但当搜索到某一步时,发现原选择并不优或者达不到目标,就退一步重新选择。这种走不通就退回再走的技术称为回溯法。特点1、出口它的关键是出口语句放置的位置(建议出口语句放在递归函数的第一行),出口语句写在最前面,方便整个函数退出。2、递归函数的参数参数是随每一次的递归操作二发生改变的,二回溯的关键就是:如果...原创 2020-02-05 00:17:52 · 5618 阅读 · 0 评论 -
leetcode掉坑经历分享
首先要承认一点,leetcode用来刷算法题,确实是提高解题思路,扩展视野的一个好东西。但是对于leetcode上题目的概述,有些情况实在不敢苟同。以下是几道算法刷题时,万万没想到的坑,分享给大家希望看过的人不会再掉进去。【leetcode 49 Group Anagrams】Given an array of strings, group anagrams together.E...原创 2020-02-22 13:59:50 · 699 阅读 · 0 评论 -
【leetcode 62】Unique Paths 求起点终点路径条数
题目A robot is located at the top-left corner of amxngrid (marked 'Start' in the diagram below).The robot can only move either down or right at any point in time. The robot is trying to reach t...原创 2020-02-08 15:36:34 · 813 阅读 · 0 评论 -
动态规划总结
动态规划三要素1、最优子问题F(10)=F(9)+F(8),就是F(10)的最优子问题,局部贪心完美的将问题分解,如果得到的F(9)和F(8)都是最优解,F(10)一定也是最优解。2、边界条件分解到最后一定变成了规模最简单的问题,即F(1)和F(2)这两个问题,不能再分解,不过没关系,他们很简单,用你的小心心算就OK了。3、状态转移方程(DP方程)假设状态转移方程为F(n)...原创 2020-02-07 02:29:14 · 401 阅读 · 0 评论 -
利用回溯法解排列组合问题
回溯法简述回溯法是一种优选的搜索法,又称试探法。按选优条件向前搜索,已达到目标。但当搜索到某一步时,发现原选择并不优或者达不到目标,就退一步重新选择。这种走不通就退回再走的技术称为回溯法。详见之前的文章回溯法总结。排列组合例题以下三道为leetcode上有关排列组合的问题,分别是46、47和48题。第一题:46.PermutationsGiven a collection...原创 2020-02-16 15:35:28 · 884 阅读 · 0 评论 -
【leetcode 40】Combination Sum II 组合总数II
题目Given a collection of candidate numbers (candidates) and a target number (target), find all unique combinations incandidateswhere the candidate numbers sums totarget.Each number incandidate...原创 2020-02-03 14:33:24 · 322 阅读 · 0 评论 -
【leetcode 39】 Combination Sum 组合总数
题目Given asetof candidate numbers (candidates)(without duplicates)and a target number (target), find all unique combinations incandidateswhere the candidate numbers sums totarget.Thesame...原创 2020-02-02 23:15:30 · 342 阅读 · 0 评论 -
【leetcode 36】 Valid Sudoku 判断数独是否有效
题目Determine if a9x9 Sudoku boardis valid.Only the filled cells need to be validatedaccording to the following rules:Each rowmust contain thedigits1-9without repetition. Each column must ...原创 2020-01-31 17:08:38 · 367 阅读 · 0 评论 -
【leetcode 121】Best Time to Buy and Sell Stock
题目:Say you have an array for which theithelement is the price of a given stock on dayi.If you were only permitted to complete at most one transaction (i.e., buy one and sell one share of the st...原创 2020-01-03 06:52:42 · 1068 阅读 · 0 评论 -
【leetcode 38】Count and Say
虽然是easy难度的题,但是题目确实有些难理解,不瞒大家,结合了百度过后的几篇文章的分析后,才初步清楚了题意,简单分析如下:1、给定第一个字符串是1;2、第二个字符串要对前一个字符串分析;3、如果前一个字符串中有连续相等的n个数字m,则输出nm,不连续则输出1m(例:1的下一个解析结果为11,11的下一个解析结果为21);清楚了题意之后,开始对题目进行思考,思路如下:1、对前一...原创 2019-12-25 23:04:15 · 1267 阅读 · 0 评论 -
【leetcode 1】两数之和
Given an array of integers, returnindicesof the two numbers such that they add up to a specific target.You may assume that each input would haveexactlyone solution, and you may not use thesame...原创 2019-12-19 22:50:52 · 749 阅读 · 0 评论 -
(七)一个寻找数组中众数的算法
Given an array of sizen, find the majority element. The majority element is the element that appearsmore than⌊ n/2 ⌋times.You may assume that the array is non-empty and the majority element原创 2016-04-14 00:15:02 · 9333 阅读 · 2 评论 -
(六)一个判断整形数组中是否有重复数字的简单算法
Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return false if every element is原创 2016-04-12 09:25:56 · 1075 阅读 · 0 评论 -
(五)判断两个词是否为变位词的算法
Given two stringssandt, write a function to determine iftis an anagram ofs.For example,s= "anagram",t= "nagaram", return true.s= "rat",t= "car", return false.==================原创 2016-04-06 15:10:49 · 2193 阅读 · 0 评论 -
(四)一个简单的删除链表中某个元素的算法
Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.Supposed the linked list is1 -> 2 -> 3 -> 4and you are given the third node with value原创 2016-04-03 11:06:38 · 798 阅读 · 0 评论 -
(三)一个将数组中特定数字放到最后的算法
Given an arraynums, write a function to move all0's to the end of it while maintaining the relative order of the non-zero elements.For example, givennums = [0, 1, 0, 3, 12], after calling you原创 2016-03-31 17:47:41 · 1843 阅读 · 0 评论
分享