LeetCode题解
lk小强
水滴穿石,一步一个脚印成长为大神
展开
-
[LeetCode]35 Search Insert Position
#include <iostream> #include <vector> using namespace std; //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...原创 2018-06-03 19:40:10 · 106 阅读 · 0 评论 -
LeetCode -1. 两数之和
给定一个整数数组和一个目标值,找出数组中和为目标值的两个数。你可以假设每个输入只对应一种答案,且同样的元素不能被重复利用。示例:给定 nums = [2, 7, 11, 15], target = 9 因为 nums[0] + nums[1] = 2 + 7 = 9 所以返回 [0, 1]//暴力解法 #include <stdio.h> #include <stdlib.h&...原创 2018-05-29 21:05:41 · 166 阅读 · 0 评论 -
[LeetCode] 26Remove Duplicates from Sorted Array 有序数组中去除重复项
#include <iostream> #include <vector> using namespace std; //给定 nums = [0, 0, 1, 1, 1, 2, 2, 3, 3, 4], //函数应该返回新的长度 5, 并且原数组 nums 的前五个元素被修改为 0, 1, 2, 3, 4。 //你不需要考虑数组中超出新长度后面的元素 class Solu...原创 2018-05-30 16:07:21 · 121 阅读 · 0 评论 -
[LeetCode]27 Remove Element 移除元素
#include <iostream> #include <vector> using namespace std; //给定一个数组 nums 和一个值 val,你需要原地移除所有数值等于 val 的元素,返回移除后数组的新长度 //不要使用额外的数组空间,你必须在原地修改输入数组并在使用 O(1) 额外空间的条件下完成 //元素的顺序可以改变。你不需要考虑数组中超出新...原创 2018-05-30 16:08:27 · 105 阅读 · 0 评论 -
华为面试题- 找出输入字符中的重复字符,再根据ascii把重复的字符从小到大排序
找出输入字符中的重复字符,再根据ascii把重复的字符从小到大排序 #include <iostream> #include <string> #include <map> using namespace std; int main() { string str; cin >> str; map<char, int> m...原创 2018-08-01 20:38:35 · 2678 阅读 · 0 评论 -
leetcode----字母二十六进制与十进制数之间的转化
字母二十六进制与十进制数之间的转化 #include <iostream> #include <string> using namespace std; class Solution { public: //二十六进制转成十进制 int titleToNumber(string s) { int n = s.size(); int res = 0; ...原创 2018-09-05 20:14:43 · 1009 阅读 · 0 评论