Leetcode 记录(201~300)】的更多相关文章

[LeetCode]201. Bitwise AND of Numbers Range 解题报告(Python) 标签: LeetCode 题目地址:https://leetcode.com/problems/bitwise-and-of-numbers-range/description/ 题目描述: Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers i…
实习面试前再完成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…
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…
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(); &…
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…
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 = -…
题目 Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers in this range, inclusive. For example, given the range [5, 7], you should return 4. 分析 题目字面意思是给定两个整数构成闭区间, 0 <= m <= n <= 2147483647 均为合法整数,求区…
1545 找出第N个二进制字符串的第K位 #分治 题目链接 题意 给定正整数\(n(\leq 20)\)与\(k\),二进制串\(S_n\)形成规则有: \(S_1 = "0"\) 当\(i>1\)时,\(S_i = S_{i-1}+"1"+reverse(invert(S_{i-1}))\) 其中\(reverse(x)\)表示左右反转字符串x,\(invert(x)\)表示翻转x中的每一位(0->1,1->0) 现要返回\(S_n\)的第\(k…
#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…