摘要:        
https://leetcode.com/problems/majority-element/ 1 class Solution { 2 public: 3 int majorityElement(vector& nums) { 4 map mymap; 5 ...    阅读全文
posted @ 2015-07-08 11:05
阿怪123
阅读(160)
评论(0)
推荐(0)
        
            
        
        
摘要:        
https://leetcode.com/problems/excel-sheet-column-number/ 1 class Solution { 2 public: 3 int titleToNumber(string s) { 4 int size=s.size();...    阅读全文
posted @ 2015-07-08 11:04
阿怪123
阅读(142)
评论(0)
推荐(0)
        
            
        
        
摘要:        
https://leetcode.com/problems/reverse-bits/ 1 class Solution { 2 public: 3 uint32_t reverseBits(uint32_t n) { 4 uint32_t res=0; 5 ...    阅读全文
posted @ 2015-07-08 11:03
阿怪123
阅读(106)
评论(0)
推荐(0)
        
            
        
        
摘要:        
https://leetcode.com/problems/happy-number/快乐数 1 class Solution { 2 public: 3 bool isHappy(int n) { 4 int res; 5 int temp; 6 ...    阅读全文
posted @ 2015-07-08 10:58
阿怪123
阅读(188)
评论(0)
推荐(0)
        
            
        
        
摘要:        
动态规划问题,定义个数组,将现阶段的所有走过的步数的最优解保存到数组中对应下标处。在进行下一步的时候,通过调用已知数组和当前节点的情况进行讨论,做出决策。 1 class Solution { 2 public: 3 int rob(vector& nums) { 4 int...    阅读全文
posted @ 2015-07-08 10:57
阿怪123
阅读(130)
评论(0)
推荐(0)
        
            
        
        
摘要:        
删除链表元素 1 /** 2 * Definition for singly-linked list. 3 * struct ListNode { 4 * int val; 5 * ListNode *next; 6 * ListNode(int x) : val(...    阅读全文
posted @ 2015-07-08 10:54
阿怪123
阅读(125)
评论(0)
推荐(0)
        
            
        
        
摘要:        
查找是否存在重复的数,直接定义map进行记录。或者用哈希也可以。 1 class Solution { 2 public: 3 bool containsDuplicate(vector& nums) { 4 map mymap; 5 int size=num...    阅读全文
posted @ 2015-07-08 10:50
阿怪123
阅读(117)
评论(0)
推荐(0)
        
            
        
        
摘要:        
同样,使用两个队列进行层间循环和层内循环。最后使用一个栈进行转置。PS:特别注意的是,对于vector的使用,在赋值的阶段会发生内存报错的情况:vector vec1;vec1[0]=1直接使用下标赋值是错误的,应使用的是push_back()函数进行数值添加。而,在调用已经赋值的变量时,可以使用下...    阅读全文
posted @ 2015-07-08 10:46
阿怪123
阅读(118)
评论(0)
推荐(0)
        
            
        
        
摘要:        
基本思想:定义一个队列q,用于作大循环,表示的每层的循环,定义一个队列q2,用作层内循环,表示每层的循环关系,只存储每层内的节点。之后就可以在二维数组中将层次关系表现出来了。 1 /** 2 * Definition for a binary tree node. 3 * struct Tree...    阅读全文
posted @ 2015-07-08 10:00
阿怪123
阅读(121)
评论(0)
推荐(0)
        
            
        
        
摘要:        
主要思想:将罗马数字的范围分块,其中,最左部分可分为13个点。对于目标数字,看它在哪个范围内,则它可以拆分为左边节点对应的字符串+(数字-左边界值)的对应罗马字符的组合。用一个递归算法来实现即可。 1 class Solution { 2 public: 3 string intToRoma...    阅读全文
posted @ 2015-07-08 09:51
阿怪123
阅读(94)
评论(0)
推荐(0)
        
 
                    
                     
                    
                 
                    
                
 
         浙公网安备 33010602011771号
浙公网安备 33010602011771号