Leetcode 记录(101~200)】的更多相关文章

1. 判断101~200之间有多少素数? package himi.hebao; /** * (1).编写函数isPrime()用来判断输入数据是否为素数 (2).遍历判断101~200之间的数据是否为素数,并且计数count * * @author Administrator * */ public class TestDemo05 { public static void main(String[] args) { int count = 0; for (int a = 101; a <=…
1 /*2 [程序 2 输出素数] 2 题目:判断 101-200 之间有多少个素数,并输出所有素数. 3 程序分析:判断素数的方法:用一个数分别去除 2 到 sqrt(这个数),如果能被整除,则表明此数不是素 4 数,反之是素数. 5 */ 6 /*分析: 7 *用一个for循环遍历101~200,再来个二层循环判定是否为素数 ,定义一个计算器,将输出的次数累加后就是素数的个数 8 */ 9 10 //[注]:百度Math.sqrt()后,发现是double类型的,所以采用强制转换 11 12…
Now, I want to just use English to explain the problem, it's about two month before the interview, so I have to practice my oral English more. And I will write my explainations in my code in order to keep this passage looking comfortable. 101. Symmet…
Leetcode 101. Symmetric Tree Easy 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 3 But the following [1,2,2,null,3,nul…
题目链接:Symmetric Tree | LeetCode OJ Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For example, this binary tree is symmetric: 1 / \ 2 2 / \ / \ 3 4 4 3 But the following is not: 1 / \ 2 2 \ \ 3 3 Note: B…
1.Two Sum naive 4.Median of Two Sorted Arrays 找两个已排序数组的中位数 直接数可以过,但很蠢,O(m+n)时间 class Solution { public: double findMedianSortedArrays(vector<int>& nums1, vector<int>& nums2) { ,p2=-; ; int len1 = nums1.size(),len2 = nums2.size(); &…
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 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…
5.回文串 几种方法: 暴力:枚举每一个字串,判断是否为回文串,复杂度O(n^3),暴力月莫不可取 dp:区间dp思想,O(n^2) 中心扩展:找每一个字符,然后往两边扩展,O(n^2) manacher算法:主要是中心扩展的一个优化,链接,这篇讲的易懂 6.ZigZag Conversion P A H N A P L S I I G Y I R 之前用了数学方法,累死了,直接搞个每行的string存一下就行 11. Container With Most Water Start by eva…
罗马数字包含以下七种字符: I, V, X, L,C,D 和 M. 字符 数值 I 1 V 5 X 10 L 50 C 100 D 500 M 1000 例如, 罗马数字 2 写做 II ,即为两个并列的 1.12 写做 XII ,即为 X + II . 27 写做  XXVII, 即为 XX + V + II . 通常情况下,罗马数字中小的数字在大的数字的右边.但也存在特例,例如 4 不写做 IIII,而是 IV.数字 1 在数字 5 的左边,所表示的数等于大数 5 减小数 1 得到的数值 4…
LeetCode真是个好东西,本来闲了一下午不想看书,感觉太荒废时间了就来刷一道题.能力有限,先把easy的题目给刷完. Determine whether an integer is a palindrome. Do this without extra space. 确定一个整数是否是回文. 做这个没有额外的空间. 这道题毕竟是easy级别的,花了大概5分钟就写出来了.我的思路就是判断回文要首尾一一对照么,如果把int转换成string类型的话比较字符就方便多了. class Solutio…
Reverse digits of an integer. Example1: x = 123, return 321Example2: x = -123, return -321 Note:The input is assumed to be a 32-bit signed integer. Your function should return 0 when the reversed integer overflows. 反转数字的整数. 示例1:x = 123,返回321示例2:x = -…
题目描述: 给定一个二叉树,检查它是否是镜像对称的. 例如,二叉树 [1,2,2,3,4,4,3] 是对称的. 1 / \ 2 2 / \ / \ 3 4 4 3 但是下面这个 [1,2,2,null,3,null,3] 则不是镜像对称的: 1 / \ 2 2 \ \ 3 3 说明: 如果你可以运用递归和迭代两种方法解决这个问题,会很加分. 思路解析: 思路一:对二叉树进行中序遍历,判断节点值是否对称分布(LeetCode测试用例未通过,但本地测试通过) public static boolea…
一.数据结构相关 链表 1. 相交链表 2. 反转链表 3. 合并两个有序链表 4. 删除排序链表中的重复元素 5. 删除链表的倒数第 n 个节点 6. 两两交换链表中的节点 7. 两数相加 II 8. 回文链表 9. 分隔链表 10.奇偶链表 数组与矩阵 1. 移动零 2. 重塑矩阵 3. 最大连续1的个数 4. 搜索二维矩阵 II 5. 有序矩阵中第 K 小的元素 6. 错误的集合 7. 寻找重复数 8. 优美的排列 II 9. 数组的度 10. 托普利茨矩阵 11. 数组嵌套 12. 最多…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 DFS BFS 日期 [LeetCode] 题目地址:https://leetcode.com/problems/symmetric-tree/ Total Accepted: 106639 Total Submissions: 313969 Difficulty: Easy 题目描述 Given a binary tree, check wheth…
#include<iostream> #include<sstream> #include<vector> std::vector<int> split(std::string& str, char delim = ' ') { std::stringstream ss(str); std::string tempStr; std::vector<int> vector; while (getline(ss, tempStr, delim…
dp/recursion的方式和是不是game无关,和game本身的规则有关:flip game不累加值,只需要一个boolean就可以.coin in a line II是从一个方向上选取,所以1d dp,而coin in a line III是两个方向,所以是2d dp flip game II: . https://repl.it/CeES https://repl.it/CeES/1 (find version) 错误点: minmax game中递归的优化条件是相反的,这题应该是对手F…
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For example, this binary tree is symmetric: 1 / \ 2 2 / \ / \ 3 4 4 3 But the following is not: 1 / \ 2 2 \ \ 3 3 Note:Bonus points if you could solve it b…
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For example, this binary tree is symmetric: 1 / \ 2 2 / \ / \ 3 4 4 3 But the following is not: 1 / \ 2 2 \ \ 3 3 Note:Bonus points if you could solve it b…
实习面试前再完成100题,争取能匀速解释清楚题 204. Count Primes 素数筛 class Solution { public: int countPrimes(int n) { ) ; n=n-; vector<,); ;i<=n;i++) { ]]=i; ;j<=prime[]&&prime[j]<=n/i;j++) { prime[prime[j]*i]=; ) break; } } ]; } };  207 210 无向图判断环 topo排序 c…
对称二叉树,就是左节点的左节点等于右节点的右节点,左节点的右节点等于右节点的左节点. 很自然就想到迭代与递归,可以创建一个新的函数,就是另一个函数不断的判断,返回在主函数. class Solution { public boolean isSymmetric(TreeNode root) { if(root == null) { return true; } else return test(root.left,root.right); } public boolean test(TreeNo…
Easy! 题目描述: 给定一个二叉树,检查它是否是镜像对称的. 例如,二叉树 [1,2,2,3,4,4,3] 是对称的. 1 / \ 2 2 / \ / \ 3 4 4 3 但是下面这个 [1,2,2,null,3,null,3] 则不是镜像对称的: 1 / \ 2 2 \ \ 3 3 说明: 如果你可以运用递归和迭代两种方法解决这个问题,会很加分. 解题思路: 判断二叉树是否是平衡树,比如有两个节点n1, n2,我们需要比较n1的左子节点的值和n2的右子节点的值是否相等,同时还要比较n1的右…
2019 1月31: 141交叉链表, 2月: 2/1: 160环形链表 ,              思路记得,但是指针里面逻辑搞错,这里不是用快慢指针而是同时的指针.:复习了141题还是有问题,把快慢指针写错了,这道题里面快指针要在满指针前面:…
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 3 But the following [1,2,2,null,3,null,3] is not: 1 / \ 2 2 \ \ 3 3 判断一…
表1: Person +-------------+---------+ | 列名 | 类型 | +-------------+---------+ | PersonId | int | | FirstName | varchar | | LastName | varchar | +-------------+---------+ PersonId 是上表主键 表2: Address +-------------+---------+ | 列名 | 类型 | +-------------+---…
判断一个整数是否是回文数.回文数是指正序(从左向右)和倒序(从右向左)读都是一样的整数. 示例 1: 输入: 121 输出: true 示例 2: 输入: -121 输出: false 解释: 从左向右读, 为 -121 . 从右向左读, 为 121- .因此它不是一个回文数. 示例 3: 输入: 10 输出: false 解释: 从右向左读, 为 01 .因此它不是一个回文数. 解答: class Solution { public boolean isPalindrome(int x) {…
实现 atoi,将字符串转为整数. 该函数首先根据需要丢弃任意多的空格字符,直到找到第一个非空格字符为止.如果第一个非空字符是正号或负号,选取该符号,并将其与后面尽可能多的连续的数字组合起来,这部分字符即为整数的值.如果第一个非空字符是数字,则直接将其与之后连续的数字字符组合起来,形成整数. 字符串可以在形成整数的字符后面包括多余的字符,这些字符可以被忽略,它们对于函数没有影响. 当字符串中的第一个非空字符序列不是个有效的整数:或字符串为空:或字符串仅包含空白字符时,则不进行转换. 若函数不能执…
给定一个 32 位有符号整数,将整数中的数字进行反转. 示例 1: 输入: 123 输出: 321 示例 2: 输入: -123 输出: -321 示例 3: 输入: 120 输出: 21 注意: 假设我们的环境只能存储 32 位有符号整数,其数值范围是 [−231,  231 − 1].根据这个假设,如果反转后的整数溢出,则返回 0. 解答: class Solution { public int reverse(int x){ if (x >0&&x<Integer.MAX…
给定一个整数数组和一个目标值,找出数组中和为目标值的两个数. 你可以假设每个输入只对应一种答案,且同样的元素不能被重复利用. 示例: 给定 nums = [2, 7, 11, 15], target = 9 因为 nums[0] + nums[1] = 2 + 7 = 9 所以返回 [0, 1] 解答: class Solution { public static int[] twoSum(int[] nums, int target) { Map<Integer, Integer> map…
Symmetric Tree Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For example, this binary tree is symmetric: 1 / \ 2 2 / \ / \ 3 4 4 3 But the following is not: 1 / \ 2 2 \ \ 3 3 Note:Bonus points if you c…
这道题难度较低,没有必要作说明. Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order. You may assume no duplicates in the array. Here are few examples.[1,3,5,6], 5…