![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
LeetCode
文章平均质量分 55
ilvseyinfu
http://qdujl.com
https://github.com/ilvseyinfu
展开
-
Encode and Decode TinyURL
博主本来英文就不好...本来规则就不是很懂..先刷两道题试试水..在知乎上看说从ac率高往低刷..结果第一道题就参考了别人的..尴尬 import java.util.*; public class Codec{ Map m =new HashMap(); public String encode(String longUrl){ String shortUrl = "http:/原创 2017-09-04 23:06:47 · 394 阅读 · 0 评论 -
Baseball Game
/** * @param {string[]} ops * @return {number} */ var calPoints = function(ops) { var arr = []; for(var i =0 ;i<ops.length ;i++){ if(ops[i] == 'D'){ var leng原创 2017-10-01 13:35:42 · 266 阅读 · 0 评论 -
Keyboard Row && Reverse Words in a String III
最近也是实在不知道该如何提升js编程水平,就用JavaScript刷LeetCode吧。 发现自己有一个习惯,晚上吃完宵夜后,必须写代码,是要靠写代码助消化么?! var findWords = function(words) { var arr2 =[]; for(var i=0 ;i<words.length ;i++){ var str = word原创 2017-09-30 23:41:12 · 177 阅读 · 0 评论 -
Average of Levels in Binary Tree
题意:求每一层的数据平均值,放到Vector里 思路:层序遍历,没啥难的 /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), le原创 2017-10-08 21:59:10 · 397 阅读 · 0 评论 -
Two Sum IV - Input is a BST
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */ clas原创 2017-10-08 20:17:17 · 262 阅读 · 0 评论 -
Invert Binary Tree
反转二叉树,没仔细看题,层序遍历的思想,写完WA了,一看错误数据,尴尬的反转错了 TreeNode* invertTree(TreeNode* root) { queue q; TreeNode* newroot = root; q.push(root); while(!q.empty()){原创 2017-10-07 23:31:08 · 200 阅读 · 0 评论 -
Merge Two Binary Trees
合并两颗二叉树,已经发现解决二叉树问题的利器就是递归~ /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL),原创 2017-09-29 14:59:36 · 179 阅读 · 0 评论 -
Hamming Distance
驾照GET,最近一直在准备笔试面试,很少有时间去看科四,回家高铁上才开始看,第二天考100分过哈哈,希望可以找到一份满意的工作 JS实现 先说两个函数; arr.reverse() 反转数组,反转后还是数组 str.split('') 将字符串转换为数组 arr.join('') 将数组元素转化为字符串 var arr = ['a','b','c','d']; var str =原创 2017-09-29 11:22:58 · 193 阅读 · 0 评论 -
Find All Numbers Disappeared in an Array
Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once. Find all the elements of [1, n] inclusive that do not appear in this array.原创 2017-10-07 12:21:35 · 186 阅读 · 0 评论 -
Single Number
O(n)的时间复杂的没有想出来,看了Discuss. int singleNumber(int* nums, int numsSize) { int num = 0; for(int i=0 ;i<numsSize; i++){ num ^= nums[i]; } return num; }原创 2017-10-07 00:27:18 · 184 阅读 · 0 评论 -
Reverse Linked List
/// 实现链表反转的两种方法 /// 1. 创建新链表 struct ListNode* reverseList(struct ListNode* head) { if(head == NULL) return NULL; struct ListNode* nlist = NULL; for(struct ListNode* p = head;p;){原创 2017-09-18 23:15:41 · 320 阅读 · 0 评论 -
237. Delete Node in a Linked List
237. Delete Node in a Linked List Write a function to delete a node (except the tail) in a singly linked list, given only access to that node. Supposed the linked list is 1 -> 2 -> 3 -> 4 and原创 2017-09-18 17:19:38 · 298 阅读 · 0 评论 -
Max Consecutive Ones
日常刷leetcode,一道简单题,脑子不是很清醒啊 int findMaxConsecutiveOnes(int* nums, int numsSize) { int count = 0 ; int result = 0; for(int i=0 ;i<numsSize ; i++){ if(nums[i]){ count++;原创 2017-09-26 10:01:56 · 149 阅读 · 0 评论 -
Maximum Binary Tree
递归求解,每次找出最的的元素作为树根,思路有点类似快排 class Solution { /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x)原创 2017-09-25 15:26:52 · 156 阅读 · 0 评论 -
Find All Duplicates in an Array
日常刷leetcode... /** * @param {number[]} nums * @return {number[]} */ var findDuplicates = function(nums) { var arr = []; for(var i=0 ;i<nums.length; i++){ var index = Math.abs(nums[原创 2017-09-25 13:00:01 · 127 阅读 · 0 评论 -
Island Perimeter
勉强算一道搜索吧。。 class Solution { public: int islandPerimeter(vector>& grid) { int row = grid.size(); int col = grid[0].size(); int sum = 0; for(int i=0 ;i<row ; i++){原创 2017-10-02 10:40:47 · 157 阅读 · 0 评论