摘要: There are N children standing in a line. Each child is assigned a rating value.You are giving candies to these children subjected to the following requirements:Each child must have at least one candy.Children with a higher rating get more candies than their neighbors.What is the minimum candies you 阅读全文
posted @ 2013-11-17 14:18 七年之后 阅读(203) 评论(0) 推荐(0) 编辑
摘要: Given an array of integers, every element appears three times except for one. Find that single one.Note: Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?思考:参考这里。class Solution {public: int singleNumber(int A[], int n) { // IMPORTANT... 阅读全文
posted @ 2013-11-17 12:31 七年之后 阅读(138) 评论(0) 推荐(0) 编辑
摘要: Given an array of integers, every element appears twice except for one. Find that single one.Note: Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?思考:位运算。class Solution {public: int singleNumber(int A[], int n) { // IMPORTANT: Pleas... 阅读全文
posted @ 2013-11-17 11:39 七年之后 阅读(166) 评论(0) 推荐(0) 编辑
摘要: A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null.Return a deep copy of the list.思考:先进行单链表复制,在定义random指针,每个结点的random指针都要遍历一次链表,时间复杂度为O(n2)。/** * Definition for singly-linked list with a random pointer. * struct RandomLi 阅读全文
posted @ 2013-11-17 03:14 七年之后 阅读(233) 评论(0) 推荐(0) 编辑