算法题
Cloud丶Shao
性格决定命运。
展开
-
【Leetcode】Top Interview Questions的代码
持续更新中。https://github.com/shaoyuncen/Algorithm/tree/master/Leetcode原创 2018-04-15 18:03:43 · 359 阅读 · 0 评论 -
【Leetcode】41. First Missing Positive
Given an unsorted integer array, find the smallest missing positive integer.Example 1:Input: [1,2,0] Output: 3 Example 2:Input: [3,4,-1,1] Output: 2 Example 3:Input: [7,8,9,11,12] Output: 1 Note:Your ...原创 2018-04-15 18:08:22 · 88 阅读 · 0 评论 -
【Leetcode】125、Valid Palindrome
回文数,仅限字母和数字的回文数,easy题,头尾指针解决。#include <iostream> using namespace std; bool isPalindrome(string s) { int start = 0, end = s.length() - 1; while (start < end) { if (!isalnum...原创 2018-04-17 16:48:32 · 143 阅读 · 0 评论 -
【Leetcode】20、Valid Parentheses
Valid系列。。这次是个左右括号匹配的题目,很容易想到用栈,先入后出的属性。easy题。#include <iostream> #include <stack> using namespace std; bool isValid(string s) { stack<char> stk; int start = 0, size = s.size(...原创 2018-04-17 16:50:26 · 104 阅读 · 0 评论 -
【Leetcode】36. Valid Sudoku
数独,也很有意思。。思路挺简单的,横向行检测,纵向列检测,九个方块区域检测。实现起来就块检测那个地方有点烦。#include <iostream> #include <vector> using namespace std; bool notRepeat(vector<char> &group) { int nums[9] = {0}; ...原创 2018-04-17 20:32:54 · 118 阅读 · 0 评论 -
【转载】【Leetcode】 324. Wiggle Sort II 解题报告
原文链接: https://blog.csdn.net/qq508618087/article/details/51337187思路是找到中位数,中位数左边的都小于中位数,中位数右边的都大于中位数。所以可以按照 1,3,5,7......(高位),0,2,4,6....(低位)来遍历,这里的映射很精巧。。。没想到。 即 (2*i + 1) % (len | 1)例0,1,2,3,4,5,6按照上面...转载 2018-04-21 20:19:15 · 228 阅读 · 0 评论