
LeetCode
123ttttttttttt
热爱技术,喜欢广交朋友,欢迎来撩!
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
LeetCode 1160. 拼写单词
题目传送门 简单的哈希。 class Solution { public: int countCharacters(vector<string>& words, string chars) { int res = 0; int ch[26] = { 0 }; for (char c : chars) { ++ch[c - 'a']; } for (s...原创 2020-03-17 10:03:32 · 141 阅读 · 0 评论 -
LeetCode 第 180 场周赛
5356. 矩阵中的幸运数 class Solution { public: vector<int> luckyNumbers (vector<vector<int>>& matrix) { vector<int> result; for(int i = 0; i < matrix.size();...原创 2020-03-15 11:41:17 · 120 阅读 · 0 评论 -
动态规划 —— 最长上升子序列
给定一个无序的整数数组,找到其中最长上升子序列的长度。题目传送门 示例: 输入: [10,9,2,5,3,7,101,18] 输出: 4 解释: 最长的上升子序列是 [2,3,7,101],它的长度是 4。 简单的dp,状态转移方程,时间复杂度O(n^2) dp[i] = max(dp[i],dp[j]+1) class Solution { public: int lengthOfLI...原创 2020-03-14 10:32:06 · 184 阅读 · 0 评论 -
LeetCode 543. 二叉树的直径
题目传送门 简单的递归题目。 class Solution { public: int ans = 0; int depth(TreeNode* rt) { if (rt == NULL) { return 0; } int l = depth(rt->left); int r = depth(rt->right); ans = max(ans, l...原创 2020-03-10 09:55:58 · 108 阅读 · 0 评论 -
LeetCode 第 179 场周赛
5352. 生成每种字符都是奇数个的字符串 class Solution { public: string generateTheString(int n) { string result; if(n&1) { for(int i = 0; i < n;i++) { ...原创 2020-03-08 13:12:56 · 143 阅读 · 0 评论 -
LeetCode 643. 子数组最大平均数 I
题目传送门 class Solution { public: double findMaxAverage(vector<int>& nums, int k) { int sum = 0; for (int i = 0; i < k; i++) { sum += nums[i]; } double result = sum * 1.0 / k; ...原创 2020-03-07 11:19:38 · 111 阅读 · 0 评论 -
LeetCode 326. 3的幂
题目传送门 class Solution { public: int v[20] = {1,3,9,27,81,243,729,2187,6561,19683,59049,177147,531441,1594323,4782969,14348907,43046721,129140163,387420489,1162261467}; bool isPowerOfThree(int n...原创 2020-03-06 15:13:27 · 141 阅读 · 0 评论 -
LeetCode 906. 超级回文数
题目传送门 class Solution { long long v[70] = { 1, 4, 9, 121, 484, 10201, 12321, 14641, 40804, 44944, 1002001, 1234321, 4008004, ...原创 2020-03-04 16:22:11 · 150 阅读 · 0 评论 -
LeetCode 14. 最长公共前缀
题目传送门 class Solution { public: string longestCommonPrefix(vector<string>& strs) { string result = ""; if(strs.size() == 0) { return result; } for (int i = 0 ; i< strs[0]...原创 2020-03-03 19:54:41 · 122 阅读 · 0 评论 -
LeetCode 面试题50. 第一个只出现一次的字符
题目传送门 class Solution { public: map<char, int> m; char firstUniqChar(string s) { for(int i = 0; i < s.length();i++) { if(m.find(s[i]) == m.end()) { m[s[i]] = 1; } el...原创 2020-03-03 08:28:42 · 198 阅读 · 0 评论 -
Leetcode 7. 整数反转
class Solution { public: int reverse(int x) { bool minus = x < 0; if (x == -2147483648) { return 0; } x = x < 0 ? -x : x; char ch[15]; sprintf(ch,"%d", x); int length = s...原创 2020-03-02 18:13:46 · 110 阅读 · 0 评论 -
717. 1-bit and 2-bit Characters
原题连接 We have two special characters. The first character can be represented by one bit 0. The second character can be represented by two bits (10 or 11). Now given a string represented by sev...原创 2018-04-13 17:23:01 · 140 阅读 · 0 评论 -
378. Kth Smallest Element in a Sorted Matrix
原题链接 Given a n x n matrix where each of the rows and columns are sorted in ascending order, find the kth smallest element in the matrix. Note that it is the kth smallest element in the sorted...原创 2018-04-17 15:15:47 · 122 阅读 · 0 评论 -
1. Two Sum
原题链接 Given an array of integers, return indices of the two numbers such that they add up to a specific target. You may assume that each input would have exactly one solution, and you may not ...原创 2018-04-17 13:42:17 · 112 阅读 · 0 评论 -
561. Array Partition I
原题链接 Given an array of 2n integers, your task is to group these integers into n pairs of integer, say (a1, b1), (a2, b2), …, (an, bn) which makes sum of min(ai, bi) for all i from 1 to n as large ...原创 2018-04-17 10:22:26 · 118 阅读 · 0 评论 -
441. Arranging Coins
原题链接 You have a total of n coins that you want to form in a staircase shape, where every k-th row must have exactly k coins. Given n, find the total number of full staircase rows that can be ...原创 2018-04-14 12:15:36 · 147 阅读 · 0 评论 -
415. Add Strings
原题链接 Given two non-negative integers num1 and num2 represented as string, return the sum of num1 and num2. Note: The length of both num1 and num2 is < 5100. Both num1 and num2 contains...原创 2018-04-14 11:41:16 · 103 阅读 · 0 评论 -
258. Add Digits
原题连接 Given a non-negative integer num, repeatedly add all its digits until the result has only one digit. For example: Given num = 38, the process is like: 3 + 8 = 11, 1 + 1 = 2. Since 2 has...原创 2018-04-14 11:34:14 · 148 阅读 · 0 评论 -
67. Add Binary
原题连接 Given two binary strings, return their sum (also a binary string). For example, a = “11” b = “1” Return “100”. 思路:模仿整数加法。 AC代码: class Solution { public: string addBinary(...原创 2018-04-14 11:21:17 · 97 阅读 · 0 评论