
leetcode
文章平均质量分 85
臻舍
这个作者很懒,什么都没留下…
展开
-
LeetCode---哈希表(hash table)
1.题目:包含重复(Contains Duplicate 2) Given an array of integers and an integer k, find out whether there there are two distinct indices i and j in the array such that nums[i] = nums[j] and the d原创 2015-06-17 15:10:04 · 1481 阅读 · 0 评论 -
Leetcode---线性数据结构(栈,链表,队列)的
1.题目:单链表的逆转(循环和递归)思路:循环:用两个指针p1,p2,p1指向node,p2指向node->next;在将p2->next指向p1前,先将p2->next保存下来。然后将p1,p2依次往后挪动递归:将链表拆分为表头节点和余下链表,将余下链表逆序后,再表头节点链接到逆序后的余下链表中注:对于线性数据结构,比较适合用迭代循环方法,而对于树状数据结构,比如二叉树,递归方法原创 2015-06-17 18:56:19 · 492 阅读 · 0 评论 -
leetcode----数字
1.题目Count Primes(计算质数个数)Count the number of prime numbers less than a non-negative number, n.计算小于n的非负数中质数的个数思路:对于每一个数k,检查是否能被2到sqrt(k)整除代码:class Solution {public: int countPrimes(int原创 2015-06-18 19:37:54 · 405 阅读 · 0 评论 -
LeetCode----树
1.题目:Invert Binary Tree/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), righ原创 2015-06-16 09:35:06 · 451 阅读 · 0 评论 -
Leetcode----处理字符串
1.Roman to Integer(将罗马数字转化为整数) Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 to 3999. 思路:1)罗马数字到整数的转换规则个位数举例I,1 】II,2】 III,3】 IV,4 】V,5原创 2015-06-15 15:24:05 · 536 阅读 · 0 评论