2017/11/6 Leetcode 日记

344. Reverse String

Write a function that takes a string as input and returns the string reversed.

class Solution {
public:
string reverseString(string s) {
int i = , sz = s.size()-;
for(i = ; i < sz; i++, sz--){
char temp = s[i];
s[i] = s[sz];
s[sz] = temp;
}
return s;
}
};

c++

class Solution:
def reverseString(self, s):
"""
:type s: str
:rtype: str
"""
return s[::-]

python3

575. Distribute Candies

Given an integer array with even length, where different numbers in this array represent different kinds of candies. Each number means one candy of the corresponding kind. You need to distribute these candies equally in number to brother and sister. Return the maximum number of kinds of candies the sister could gain.

Note:

  1. The length of the given array is in range [2, 10,000], and will be even.
  2. The number in given array is in range [-100,000, 100,000].
class Solution {
public:
int distributeCandies(vector<int>& candies) {
int sz = candies.size();
unordered_set<int> sets = {};
unordered_set<int>::const_iterator got;
for(int i = ; i < sz; i++){
got = sets.find(candies[i]);
if (got == sets.end())
sets.insert(candies[i]);
}
if (sets.size() <= sz/) return sets.size();
else return sz/;
}
};

c++

2017/11/6 Leetcode 日记的更多相关文章

  1. 2017/11/22 Leetcode 日记

    2017/11/22 Leetcode 日记 136. Single Number Given an array of integers, every element appears twice ex ...

  2. 2017/11/21 Leetcode 日记

    2017/11/21 Leetcode 日记 496. Next Greater Element I You are given two arrays (without duplicates) num ...

  3. 2017/11/13 Leetcode 日记

    2017/11/13 Leetcode 日记 463. Island Perimeter You are given a map in form of a two-dimensional intege ...

  4. 2017/11/20 Leetcode 日记

    2017/11/14 Leetcode 日记 442. Find All Duplicates in an Array Given an array of integers, 1 ≤ a[i] ≤ n ...

  5. 2017/11/9 Leetcode 日记

    2017/11/9 Leetcode 日记 566. Reshape the Matrix In MATLAB, there is a very useful function called 'res ...

  6. 2017/11/7 Leetcode 日记

    2017/11/7 Leetcode 日记 669. Trim a Binary Search Tree Given a binary search tree and the lowest and h ...

  7. 2017/11/5 Leetcode 日记

    2017/11/5 Leetcode 日记 476. Number Complement Given a positive integer, output its complement number. ...

  8. 2017/11/3 Leetcode 日记

    2017/11/3 Leetcode 日记 654. Maximum Binary Tree Given an integer array with no duplicates. A maximum ...

  9. jingchi.ai 2017.11.25-26 Onsite面试

    时间:2017.11.25 - 11.26 地点:安徽安庆 来回路费报销,住宿报销. day1: 大哥哥问了我一个实际中他们遇到的问题.有n个点,将点进行分块输出,输出各个块的均值点.具体就是100* ...

随机推荐

  1. GridControl详解(七)事件

    private void gridView1_RowCellClick(object sender, DevExpress.XtraGrid.Views.Grid.RowCellClickEventA ...

  2. Windows Live Writer博客草稿迁移的一种解决方案

    作为一个苦逼的码农,喜欢写博客做总结是很正常的事,写博客写的久的人都接触过各种客户端工具,最流行的就是Windows Live Writer了. 作为一个苦逼的码农,换电脑也是很经常的事,经常会出现一 ...

  3. 安装Docker-ce

    Docker Engine改为Docker CE(社区版) 它包含了CLI客户端.后台进程/服务以及API.用户像以前以同样的方式获取.Docker Data Center改为Docker EE(企业 ...

  4. 29、最小的K个数

    一.题目 输入n个整数,找出其中最小的K个数.例如输入4,5,1,6,2,7,3,8这8个数字,则最小的4个数字是1,2,3,4,. 二.解法 import java.util.ArrayList; ...

  5. webconfig的配置解析

    <?xml version="1.0"?> <!--注意: 除了手动编辑此文件以外,您还可以使用 Web 管理工具来配置应用程序的设置.可以使用 Visual S ...

  6. python并发编程之threading线程(一)

    进程是系统进行资源分配最小单元,线程是进程的一个实体,是CPU调度和分派的基本单位,它是比进程更小的能独立运行的基本单位.进程在执行过程中拥有独立的内存单元,而多个线程共享内存等资源. 系列文章 py ...

  7. SVM问题再理解与分析——我的角度

    SVM问题再理解与分析--我的角度 欢迎关注我的博客:http://www.cnblogs.com/xujianqing/ 支持向量机问题 问题先按照几何间隔最大化的原则引出他的问题为 上面的约束条件 ...

  8. rocketmq 记

    Rocketmq选型 Rocket是一个专业的队列服务,性能优于Rabbitmq,优势是性能和并发,源于Kafka的扩展版,增强了数据的可靠性. Rocketmq的队列类型 普通队列,广播队列.顺序队 ...

  9. Petrozavodsk Summer Training Camp 2017

    Petrozavodsk Summer Training Camp 2017 Problem A. Connectivity 题目描述:有\(n\)个点,现不断地加边.每条边有一种颜色,如果一个点对\ ...

  10. c++环境配置 Eclipse+mingw-get-setup

    1,到官网下载eclipse  和  mingw-get-setup 2,先安装eclipse,然后等着... 3,再安装mingw-get-setup, 等待...安装完成后打开,选择basic s ...