- 博客(9)
- 收藏
- 关注
原创 【leetcode】3. Longest Substring Without Repeating Characters
思路:begin记录longest substring开始的位置;longest当前substring的长度;map存放字符的index。实质上是维护了一个substring区间,使得substring内的所有字符都是独一无二的。class Solution {public: int lengthOfLongestSubstring(string s) { if (...
2020-01-30 00:47:32 79
原创 【leetcode】2. Add Two Numbers
思路:第一个ListNode单独处理,其余的ListNode都是常规操作。/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */c...
2020-01-29 01:14:12 89
原创 【leetcode】1. Two Sum
思路:map是关键。用map对另一个number的index进行映射。class Solution {public: vector<int> twoSum(vector<int>& nums, int target) { unordered_map<int, int> nums_map; //内部实现是基...
2020-01-29 00:38:37 78
原创 快速排序算法
#include <iostream>#include <assert.h>using namespace std;int Partition(int *arr, int low, int high) { if (low > high) { //未检验low和high合法性 assert(0); } if (low == high) { retu...
2020-01-28 22:33:31 66
原创 好用的桌面搜索引擎(如果你的快捷方式很多,可能会需要它)
软件叫“火柴”。双击Ctrl键就会在屏幕中间显示一个搜索框,再次双击Ctrl键就会消失,非常方便。
2020-01-12 12:21:19 929
原创 面试题17:打印从1到最大的n位数
我自己的实现,常规思路#include<iostream>#include <assert.h>using namespace std;bool increment_str(char *num_str, int str_len) { // return false表示超过了num_str所表示的最大范围。 // 应该检查num_str是否全是数字,这里暂时...
2020-01-06 18:27:04 81
原创 面试题16:数值的整数次方
#include<iostream>#include <assert.h>using namespace std;bool equal(double d1, double d2) { return abs(d1 - d2) < 0.000001; // double精度设置}double Power(double base, int exponent)...
2020-01-05 23:28:10 68
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人