随笔分类 -  LeetCode OJ

1 2 3 下一页

a common method to rotate the image
摘要:1 /* 2 * clockwise rotate 3 * first reverse up to down, then swap the symmetry 4 * 1 2 3 7 8 9 7 4 1 5 * 4 5 6 => 4 5 6 => 8 5 2 6 * ... 阅读全文

posted @ 2015-08-27 21:18 Stomach_ache 阅读(168) 评论(0) 推荐(0) 编辑

LeeCode-Single Number III
摘要:Given an array of numbersnums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements t... 阅读全文

posted @ 2015-08-23 18:44 Stomach_ache 阅读(228) 评论(0) 推荐(0) 编辑

LRU Cache -- LeetCode
摘要:Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations:getandset.get(key)- Get the valu... 阅读全文

posted @ 2014-12-20 14:11 Stomach_ache 阅读(320) 评论(0) 推荐(0) 编辑

LeetCode --- Convert Sorted Array to Binary Search Tree
摘要:题目链接Problem discription:Given an array where elements are sorted in ascending order, convert it to a height balanced BST.Accepted Code: 1 /** 2 * Def... 阅读全文

posted @ 2014-06-14 17:54 Stomach_ache 阅读(134) 评论(0) 推荐(0) 编辑

LeetCode --- Valid Parentheses
摘要:题目链接Problem discriptionGiven a string containing just the characters'(',')','{','}','['and']', determine if the input string is valid.The brackets mus... 阅读全文

posted @ 2014-06-12 11:35 Stomach_ache 阅读(86) 评论(0) 推荐(0) 编辑

LeetCode ---- Merge Sorted Array
摘要:题目链接Problem discriptionGiven two sorted integer arrays A and B, merge B into A as one sorted array.Note:You may assume that A has enough space (size t... 阅读全文

posted @ 2014-06-12 10:31 Stomach_ache 阅读(142) 评论(0) 推荐(0) 编辑

LeetCode --- Populating Next Right Pointers in Each Node II
摘要:题目链接Problem description:Follow up for problem "Populating Next Right Pointers in Each Node".What if the given tree could be any binary tree? Would you... 阅读全文

posted @ 2014-06-10 14:55 Stomach_ache 阅读(149) 评论(0) 推荐(0) 编辑

LeetCode --- Populating Next Right Pointers in Each Node
摘要:题目链接Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each next po... 阅读全文

posted @ 2014-06-10 14:11 Stomach_ache 阅读(111) 评论(0) 推荐(0) 编辑

LeetCode --- Remove Element
摘要:题目链接题意:给出长度为n的数组,和整数elem, 要求删除数组中存在的elem,返回最终的数组长度。附上代码: 1 class Solution { 2 public: 3 int removeElement(int A[], int n, int elem) { 4 //... 阅读全文

posted @ 2014-06-08 21:05 Stomach_ache 阅读(154) 评论(0) 推荐(0) 编辑

LeetCode --- Pow(x, n)
摘要:题目链接题意:实现pos(x, n)功能, 其中x为double类型,n为int类型附上代码: 1 class Solution { 2 public: 3 double pow(double x, int n) { 4 // handle several particula... 阅读全文

posted @ 2014-06-08 20:39 Stomach_ache 阅读(148) 评论(0) 推荐(0) 编辑

LeetCode --- Rotate Image
摘要:题目链接题意: 给出 n * n的矩阵,要求将矩阵顺时针旋转90°(不使用额外空间) 1 /* 2 Basically, divide the array into 4 along the diagonals, 3 then for each element in the top ... 阅读全文

posted @ 2014-06-08 17:23 Stomach_ache 阅读(154) 评论(0) 推荐(0) 编辑

LeetCode --- Balanced Binary Tree
摘要:题目链接题意: 给定一棵二叉树, 判断是否为平衡二叉树, 这里的平衡二叉树指的是:每个结点的左右子树的深度之差不超过1。附上代码: 1 /** 2 * Definition for binary tree 3 * struct TreeNode { 4 * int val; 5 * ... 阅读全文

posted @ 2014-06-08 14:01 Stomach_ache 阅读(150) 评论(0) 推荐(0) 编辑

LeetCode --- Minimum Depth of Binary Tree
摘要:题目链接求二叉树最小深度,最小深度指的是:从根节点走到最近的叶子结点的最短长度附上代码: 1 /** 2 * Definition for binary tree 3 * struct TreeNode { 4 * int val; 5 * TreeNode *left; 6... 阅读全文

posted @ 2014-06-08 12:31 Stomach_ache 阅读(126) 评论(0) 推荐(0) 编辑

LeetCode --- Validate Binary Search Tree
摘要:题目链接判断一颗二叉树是否是二叉搜索树(二叉排序树),也就是BST如果该二叉树是BST, 那么对其中序遍历,所得序列一定是单调递增的(不考虑有重复数值的情况)附上代码: 1 /** 2 * Definition for binary tree 3 * struct TreeNode { 4 *... 阅读全文

posted @ 2014-06-05 12:19 Stomach_ache 阅读(97) 评论(0) 推荐(0) 编辑

LeetCode --- Roman to Integer
摘要:题目链接将罗马数字转换为十进制整数。数据范围为:1~3999罗马数字由7种字母组成,按照特定规则可以组成任意正整数, 需要注意的是罗马数字中没有”0“.关于罗马数字具体可以看:这里附上代码: 1 class Solution { 2 public: 3 int romanToInt(stri... 阅读全文

posted @ 2014-06-04 15:48 Stomach_ache 阅读(108) 评论(0) 推荐(0) 编辑

LeetCode --- Maximum Depth of Binary Tree
摘要:题目链接求树的最大深度附上代码: 1 /** 2 * Definition for binary tree 3 * struct TreeNode { 4 * int val; 5 * TreeNode *left; 6 * TreeNode *right; 7 ... 阅读全文

posted @ 2014-06-04 15:19 Stomach_ache 阅读(123) 评论(0) 推荐(0) 编辑

LeetCode --- Minimum Path Sum
摘要:题目链接简单倒推附上代码: 1 class Solution { 2 public: 3 int minPathSum(vector > &grid) { 4 int n = (int)grid.size(); 5 if (n == 0) return 0; ... 阅读全文

posted @ 2014-06-04 14:38 Stomach_ache 阅读(142) 评论(0) 推荐(0) 编辑

LeetCode --- Partition List
摘要:题目链接又是一个考察对链表基本操作的题目附上代码: 1 /** 2 * Definition for singly-linked list. 3 * struct ListNode { 4 * int val; 5 * ListNode *next; 6 * Lis... 阅读全文

posted @ 2014-06-02 11:08 Stomach_ache 阅读(158) 评论(1) 推荐(0) 编辑

LeetCode --- Valid Palindrome
摘要:题目链接判断字符串是否为回文串。附上代码: 1 class Solution { 2 public: 3 bool isPalindrome(string s) { 4 if (s.empty()) return true; // consider empty string ... 阅读全文

posted @ 2014-05-29 21:54 Stomach_ache 阅读(130) 评论(0) 推荐(0) 编辑

LeetCode --- Longest Consecutive Sequence
摘要:题目链接对unordered_set和set的内部实现还不了解,只知道前者是hash实现的,后者是用R-B-Tree实现。有时间需要读下源码。附上代码: 1 class Solution { 2 public: 3 int longestConsecutive(vector &num) { ... 阅读全文

posted @ 2014-05-29 12:28 Stomach_ache 阅读(102) 评论(0) 推荐(0) 编辑

1 2 3 下一页
< 2025年2月 >
26 27 28 29 30 31 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 1
2 3 4 5 6 7 8

导航

统计

点击右上角即可分享
微信分享提示