leetcode819
摘要:public class Solution { public string MostCommonWord(string paragraph, string[] banned) { //"a, a, a, a, b,b,b,c, c" paragraph = paragraph.ToLower().Replac...
阅读全文
posted @
2018-09-30 22:50
Sempron2800+
阅读(128)
推荐(0)
leetcode844
摘要:class Solution { public: bool backspaceCompare(string S, string T) { stack ST1; for (int i = 0; i ST2; for (int i = 0; i < T.length(); i++) { char c =...
阅读全文
posted @
2018-09-30 22:33
Sempron2800+
阅读(125)
推荐(0)
leetcode706
摘要:class MyHashMap { public: vector hashMap; /** Initialize your data structure here. */ MyHashMap() { } /** value will always be non-negative. */ void put(int key,...
阅读全文
posted @
2018-09-30 20:55
Sempron2800+
阅读(116)
推荐(0)
leetcode830
摘要:public class Solution { public IList> LargeGroupPositions(string S) { //"babaaaabbb" var list = new List>(); int len = S.Length; if...
阅读全文
posted @
2018-09-30 20:45
Sempron2800+
阅读(105)
推荐(0)
leetcode697
摘要:public class Solution { public int FindShortestSubArray(int[] nums) { //先找到最大频度的数字都有哪些,加入到一个集合中 var dic = new Dictionary(); var dic...
阅读全文
posted @
2018-09-30 18:46
Sempron2800+
阅读(104)
推荐(0)
leetcode773
摘要:使用两种语言实现,先贴C++的 下面贴出C#的
阅读全文
posted @
2018-09-30 17:52
Sempron2800+
阅读(151)
推荐(0)
leetcode783
摘要:对BST树进行中序遍历,得到递增序列,然后依次计算相邻两元素之间的差,并保存最小的差。
阅读全文
posted @
2018-09-30 16:44
Sempron2800+
阅读(82)
推荐(0)
leetcode717
摘要:class Solution { public: bool isOneBitCharacter(vector& bits) { int len = bits.size(); if (len == 1) { if (bits[0] == 0) { return t...
阅读全文
posted @
2018-09-30 16:06
Sempron2800+
阅读(91)
推荐(0)
leetcode427
摘要:本题不会做,从网上找到了python3的解法,记录如下。
阅读全文
posted @
2018-09-30 15:51
Sempron2800+
阅读(108)
推荐(0)
leetcode796
摘要:public class Solution { public bool RotateString(string A, string B) { string temp = A; int len = A.Length; int lenB = B.Length; ...
阅读全文
posted @
2018-09-30 14:14
Sempron2800+
阅读(88)
推荐(0)
leetcode788
摘要:public class Solution { public int RotatedDigits(int N) { int sum = 0; for (int i = 1; i <= N; i++) { var str = i.ToString(...
阅读全文
posted @
2018-09-30 13:56
Sempron2800+
阅读(95)
推荐(0)
leetcode696
摘要:本题先寻找字符串中0变1,或者1变0的位置作为分隔位置。然后从这个分隔位置同时向左、右两侧搜索。 找到的左连续串和右连续串,都进行累计。
阅读全文
posted @
2018-09-30 12:52
Sempron2800+
阅读(121)
推荐(0)
leetcode690
摘要:本题是分支限界法,广度优先搜索,使用map加速查询,防止超时。
阅读全文
posted @
2018-09-30 11:35
Sempron2800+
阅读(115)
推荐(0)
leetcode695
摘要:本题属于分支限界的题目,广度优先进行搜索。利用访问的数组Visited,记录已经走过的路径,以减少重复计算。
阅读全文
posted @
2018-09-30 10:59
Sempron2800+
阅读(204)
推荐(0)
leetcode812
摘要:这道题没什么思路,参照网上的答案,再此先做一个记录吧。
阅读全文
posted @
2018-09-30 09:25
Sempron2800+
阅读(117)
推荐(0)
leetcode784
摘要:这道题经过独立思考,通过使用二进制编码的方式来进行处理。分几个步骤一层一层的处理,最终解决了,这道题感觉应该属于medimu级别。 另一种解法,使用回溯法: 再提供一种回溯法的思路,使用python实现:
阅读全文
posted @
2018-09-29 21:52
Sempron2800+
阅读(127)
推荐(0)
leetcode888
摘要:class Solution { public: int Binary_Search(vector x, int N, int keyword) { int low = 0, high = N - 1, mid; while (low fairCandySwap(vector& A, vector& B) { int sumA =...
阅读全文
posted @
2018-09-29 17:35
Sempron2800+
阅读(134)
推荐(0)
leetcode896
摘要:class Solution { public: bool isMonotonic(vector& A) { if (A.size() A[i + 1])//应该是增序列,但遇到左>右,则表示false { return false; } ...
阅读全文
posted @
2018-09-29 16:58
Sempron2800+
阅读(101)
推荐(0)
leetcode892
摘要:这道题因为有0的情况,因此不能使用投影的方法,需要遍历每一个元素,单独处理。
阅读全文
posted @
2018-09-29 14:27
Sempron2800+
阅读(180)
推荐(0)
leetcode824
摘要:class Solution { public: void SplitString(const string& s, vector& v, const string& c) { string::size_type pos1, pos2; pos2 = s.find(c); pos1 = 0; while (strin...
阅读全文
posted @
2018-09-29 12:41
Sempron2800+
阅读(95)
推荐(0)
leetcode762
摘要:class Solution { public: bool IsPrime(int n) { if (n == 1) { return false; } if (n == 2 || n == 3) { return true; } ...
阅读全文
posted @
2018-09-29 11:45
Sempron2800+
阅读(109)
推荐(0)
leetcode693
摘要:class Solution { public: bool hasAlternatingBits(int n) { int last = -1; while (n) { int x = n & 1; if (last == -1) { ...
阅读全文
posted @
2018-09-29 11:06
Sempron2800+
阅读(90)
推荐(0)
leetcode897
摘要:这道题用C++来写,在本地执行正常,但是使用OJ判断输出结果是空,暂时不清楚原因。代码如下: 保留原有逻辑,修改为C#代码,则通过所有测试,代码如下: 不知是leetcode的判断机制问题,还是我的C++写法的问题。之后还是尽量使用C#吧。
阅读全文
posted @
2018-09-29 00:29
Sempron2800+
阅读(193)
推荐(0)
leetcode868
摘要:class Solution { public: int binaryGap(int N) { int position = 0; vector V; while (N) { if (N & 1)//N&1==1,表示最后一位是1 { V.pus...
阅读全文
posted @
2018-09-28 19:45
Sempron2800+
阅读(93)
推荐(0)
leetcode893
摘要:class Solution { public: int numSpecialEquivGroups(vector& A) { set ST; for (auto a : A) { vector V1; vector V2; for (int i = 0; i < a...
阅读全文
posted @
2018-09-28 19:02
Sempron2800+
阅读(117)
推荐(0)
leetcode682
摘要:class Solution { public: int calPoints(vector& ops) { stack ST; int sum = 0; for (auto o : ops) { if (o == "C") { int n = S...
阅读全文
posted @
2018-09-28 18:27
Sempron2800+
阅读(89)
推荐(0)
leetcode766
摘要:本题经过一下午的思考,终于解出来了。使用的是层次遍历的思想。
阅读全文
posted @
2018-09-28 17:34
Sempron2800+
阅读(116)
推荐(0)
leetcode884
摘要:class Solution { public: void SplitString(const string& s, vector& v, const string& c) { string::size_type pos1, pos2; pos2 = s.find(c); pos1 = 0; while (strin...
阅读全文
posted @
2018-09-28 07:36
Sempron2800+
阅读(114)
推荐(0)
leetcode811
摘要:class Solution { public: void SplitString(const string& s, vector& v, const string& c) { string::size_type pos1, pos2; pos2 = s.find(c); pos1 = 0; while (strin...
阅读全文
posted @
2018-09-27 22:40
Sempron2800+
阅读(112)
推荐(0)
leetcode821
摘要:vector shortestToChar(string S, char C) { vector V; const int N = 10001; int AYC[N]; int countC = 0; for (int i = 0; i < S.size(); i++) { if (S[i] == C) { ...
阅读全文
posted @
2018-09-27 22:14
Sempron2800+
阅读(87)
推荐(0)
leetcode872
摘要:class Solution { public: vector v1; vector v2; void GetLeaf(TreeNode* tree, int type) { if (tree->left != NULL || tree->right != NULL) { if (tree->left != ...
阅读全文
posted @
2018-09-27 20:41
Sempron2800+
阅读(90)
推荐(0)
leetcode700
摘要:class Solution { public: TreeNode* searchBST(TreeNode* root, int val) { if (root == NULL) { return nullptr; } if (root->val == val) { ...
阅读全文
posted @
2018-09-27 18:56
Sempron2800+
阅读(127)
推荐(0)
leetcode806
摘要:vector numberOfLines(vector& widths, string S) { map MAP; MAP.insert(make_pair('a', widths[0])); MAP.insert(make_pair('b', widths[1])); MAP.insert(make_pair('c', widths[2])); MAP....
阅读全文
posted @
2018-09-27 18:46
Sempron2800+
阅读(201)
推荐(0)
leetcode876
摘要:class Solution { public: ListNode* middleNode(ListNode* head) { if (head == NULL) { return nullptr; } vector List; List.push_back(head); ...
阅读全文
posted @
2018-09-27 18:26
Sempron2800+
阅读(115)
推荐(0)
leetcode908
摘要:int smallestRangeI(vector& A, int K) { int min = INT_MAX; int max = INT_MIN; for (auto a : A) { if (min > a) { min = a; } if (max 2 * K) ...
阅读全文
posted @
2018-09-27 18:09
Sempron2800+
阅读(96)
推荐(0)
leetcode883
摘要:int projectionArea(vector>& grid) { int sum = 0; int row_max = 0; int col_max = 0; for (int i = 0; i < grid.size(); i++) { row_max = 0; for (int j = 0; j < grid[0...
阅读全文
posted @
2018-09-27 17:36
Sempron2800+
阅读(114)
推荐(0)
leetcode867
摘要:vector> transpose(vector>& A) { vector> V; int RowLen = A.size(); int ColLen = A[0].size(); for (int j = 0; j v; for (int i = 0; i < RowLen; i++) { v....
阅读全文
posted @
2018-09-27 14:53
Sempron2800+
阅读(110)
推荐(0)
leetcode728
摘要:vector selfDividingNumbers(int left, int right) { vector V; for (int i = left; i = 1 && i <= 9) { V.push_back(i); continue; } bool tag = true; ...
阅读全文
posted @
2018-09-27 14:13
Sempron2800+
阅读(103)
推荐(0)
leetcode852
摘要:int peakIndexInMountainArray(vector& A) { int Len = A.size(); int position = -1; for (int i = 1; i A[i - 1] && A[i] > A[i + 1]) { position = i; break; ...
阅读全文
posted @
2018-09-27 13:48
Sempron2800+
阅读(132)
推荐(0)
leetcode832
摘要:vector> flipAndInvertImage(vector>& A) { vector> B; for (int i = 0; i Row = A[i]; vector Row2; for (int j = Row.size() - 1; j >= 0; j--) { int n = Row[j];...
阅读全文
posted @
2018-09-27 13:31
Sempron2800+
阅读(99)
推荐(0)
leetcode804
摘要:int uniqueMorseRepresentations(vector& words) { map st; st.insert(make_pair('a', ".-")); st.insert(make_pair('b', "-...")); st.insert(make_pair('c', "-.-.")); st.insert(make_pair(...
阅读全文
posted @
2018-09-27 13:10
Sempron2800+
阅读(93)
推荐(0)
leetcode905
摘要:vector sortArrayByParity(vector& A) { vector EVEN;//偶数 vector ODD;//奇数 for (auto a : A) { if (a % 2 == 0)//EVEN { EVEN.push_back(a); } else...
阅读全文
posted @
2018-09-27 12:00
Sempron2800+
阅读(97)
推荐(0)
leetcode709
摘要:string toLowerCase(string str) { transform(str.begin(), str.end(), str.begin(), ::tolower); return str; }
阅读全文
posted @
2018-09-27 11:52
Sempron2800+
阅读(99)
推荐(0)
leetcode771
摘要:int numJewelsInStones(string J, string S) { set st; int count = 0; for (auto c : J) { st.insert(c); } for (auto s : S) { if (st.find(s) != st.end()) ...
阅读全文
posted @
2018-09-27 11:49
Sempron2800+
阅读(138)
推荐(0)
leetcode669
摘要:本题目是使用递归处理,根据当前的值来判断剪去的子树,保留剩下的子树。
阅读全文
posted @
2018-09-27 10:52
Sempron2800+
阅读(102)
推荐(0)
leetcode665
摘要:这道题目,主要是判断相邻的两个值的大小,并按照要求的方式,将数组的数值都修正为符合要求的值。 然后通过一次的遍历,计算所累积的移动次数。
阅读全文
posted @
2018-09-27 10:20
Sempron2800+
阅读(122)
推荐(0)
leetcode661
摘要:vector> imageSmoother(vector>& M) { const int N = 151; vector> V; for (int i = 0; i m1 = M[i]; vector m2; for (int j = 0; j = 0 && x = 0 && y <= m1.size() - 1) ...
阅读全文
posted @
2018-09-26 20:40
Sempron2800+
阅读(91)
推荐(0)
leetcode653
摘要:class Solution { public: bool findTarget(TreeNode* root, int k) { queue Q; vector V; if (root != NULL) { Q.push(*root); while (!Q.empty()) ...
阅读全文
posted @
2018-09-26 19:52
Sempron2800+
阅读(109)
推荐(0)
leetcode657
摘要:bool judgeCircle(string moves) { int V = 0;//垂直位移 int H = 0;//水平位移 for (auto m : moves) { if (m == 'U') { V++; } else if (m == 'D') ...
阅读全文
posted @
2018-09-26 19:03
Sempron2800+
阅读(107)
推荐(0)
leetcode645
摘要:vector findErrorNums(vector& nums) { const int N = 10001; int S[N]; int n = nums.size(); for (int i = 0; i R; R.push_back(dup); R.push_back(miss); return R; }
阅读全文
posted @
2018-09-26 17:50
Sempron2800+
阅读(98)
推荐(0)
leetcode643
摘要:double findMaxAverage(vector& nums, int k) { double max = INT_MIN; int len = nums.size(); if (len <= 4) { int sum = 0; for (int i = 0; i < len; i++) { ...
阅读全文
posted @
2018-09-26 17:00
Sempron2800+
阅读(103)
推荐(0)
leetcode633
摘要:用开方的思想来解题。 补充一个phthon的实现,使用双指针思想:
阅读全文
posted @
2018-09-26 16:40
Sempron2800+
阅读(112)
推荐(0)
leetcode637
摘要:层次遍历,计算每一层的节点值,然后求平均值。
阅读全文
posted @
2018-09-26 16:21
Sempron2800+
阅读(134)
推荐(0)
leetcode617
摘要:这道题想了很久,并没有掌握思想,写了很多,也没有解决。先贴出思考的过程。 下面列出正确的解法。 补充一个python的实现,和上面的C++的思路基本一样,只是我个人感觉更容易理解一些:
阅读全文
posted @
2018-09-26 13:21
Sempron2800+
阅读(158)
推荐(0)
leetcode559
摘要:另一种解法,递归实现: 递归的逻辑是:当前节点的最大深度,一定是深度最大的子节点的深度+1。
阅读全文
posted @
2018-09-25 21:11
Sempron2800+
阅读(136)
推荐(0)
leetcode482
摘要:这道题主要使用了C++的几个API,大小写转化,字符串替换。其余的逻辑都比较简单。而且经查资料,string类字符串拼接的速度使用+=的速度是很快的。以下代码,也是用的+=来拼接字符串。
阅读全文
posted @
2018-09-25 20:13
Sempron2800+
阅读(114)
推荐(0)
leetcode458
摘要:原本没有思路,参考了网上的解题思路,自己独立完成了代码。
阅读全文
posted @
2018-09-25 19:28
Sempron2800+
阅读(85)
推荐(0)
leetcode443
摘要:使用两个数组分别记录字符和对应的数字,然后清除原来的vector,重新向里面添加元素。注意判断1个字符时,不将'1'加入vector。
阅读全文
posted @
2018-09-25 16:17
Sempron2800+
阅读(126)
推荐(0)
leetcode429
摘要:这道题目是属于树的层次遍历,使用两层的队列非空判断。 精简版本的代码:
阅读全文
posted @
2018-09-25 14:24
Sempron2800+
阅读(110)
推荐(0)
leetcode55
摘要:这是贪心算法类型的题目。 补充一个python的实现: 补充一个双指针思路的解决方案,使用python实现:
阅读全文
posted @
2018-09-23 19:07
Sempron2800+
阅读(157)
推荐(0)
leetcode874
摘要:这道题直接按照题意来解,建立坐标系和移动方案,思路是比较简单的。只是需要注意需要使用set来判断是否遇到障碍,否则会超时。
阅读全文
posted @
2018-09-23 16:01
Sempron2800+
阅读(148)
推荐(0)