【leetcode刷题笔记】Add Binary】的更多相关文章

Given a binary tree, return the preorder traversal of its nodes' values. For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3 return [1,2,3]. Note: Recursive solution is trivial, could you do it iteratively? 解题:应该是很简单的一道题,纠结了好久T_T 基本思路很简单,用栈模拟就可以了.首先根节…
Given two binary strings, return their sum (also a binary string). For example, a = "11" b = "1" Return "100". 详细一位一位地加即可了,考虑进位的问题.还有最后记得把生成的string反过来再返回,由于我们是从最低位開始加的. public class Solution { public String addBinary(String a…
Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level). For example:Given binary tree {3,9,20,#,#,15,7}, / \ / \ return its level order traversal as: [ [], [,], [,] ] 题解:二叉树的层次遍历,用队列实现.重点在…
Given a binary tree, return the inorder traversal of its nodes' values. For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3 return [1,3,2]. Note: Recursive solution is trivial, could you do it iteratively? 解题:果然不能晚上做题,效率好低.看了讨论才学会的解法.设置一个指针next指向当前访问的…
Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root). For example:Given binary tree {3,9,20,#,#,15,7}, 3 / \ 9 20 / \ 15 7 return its bottom-up level order tr…
主要用于记录在LeetCode刷题的过程中学习到的一些思想和自己的想法,希望通过leetcode提升自己的编程素养 :p 高效leetcode刷题小诀窍(这只是目前对我自己而言的小方法,之后会根据自己的切身经历更新): 算法不是纯粹拼智商的,智商高,就一定很厉害,不够聪明,就一定不行.算法是一种技能,是可以通过科学合理的方式训练出来的能力.目前国内大厂的算法考察,基本不会超过leetcode 中等难度,上限难度基本都是leetcode 中等题里面的中等难度 基本的算法数据结构是有限的.比如说链表…
本人算法还是比较菜的,因此大部分在刷基础题,高手勿喷 选择Python进行刷题,因为坑少,所以不太想用CPP: 1.买股票的最佳时期2 给定一个数组,它的第 i 个元素是一支给定股票第 i 天的价格. 设计一个算法来计算你所能获取的最大利润.你可以尽可能地完成更多的交易(多次买卖一支股票). 注意:你不能同时参与多笔交易(你必须在再次购买前出售掉之前的股票). 思路:买高不买低,向上即可 class Solution(object): def maxProfit(self, prices): "…
学好算法很重要,然后要学好算法,大量的练习是必不可少的,LeetCode是我经常去的一个刷题网站,上面的题目非常详细,各个标签的题目都有,可以整体练习,本公众号后续会带大家做一做上面的算法题. 官方链接:https://leetcode-cn.com/problemset/all/ 一.题意 难度:中等 https://leetcode-cn.com/problems/integer-to-roman/ 罗马数字包含以下七种字符:I, V, X, L,C,D 和 M. 字符 数值 I 1 V 5…
1.题目 67. Add Binary——easy Given two binary strings, return their sum (also a binary string). The input strings are both non-empty and contains only characters 1 or 0. Example 1: Input: a = "11", b = "1"Output: "100"Example 2:…
1.何为双指针 双指针主要用来遍历数组,两个指针指向不同的元素,从而协同完成任务.我们也可以类比这个概念,推广到多个数组的多个指针. 若两个指针指向同一数组,遍历方向相同且不会相交,可以称之为滑动窗口(两个指针包围的区域为当前的窗口),经常用于区间搜索. 若两个指针指向同一数组,但是遍历方向相反,那我们可以用来进行搜索,这时我们要搜索的数组往往需要排序好. 2.双指针类型 在目前的刷到过的题目种,遇到了两类双指针问题 第一类是快慢指针,顾名思义,就是一个fast指针,一个slow指针,一前一后,…