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. $.extend()与$.fn.extend()

    jQuery.extend(object) 扩展jQuery对象本身.用来在jQuery命名空间上增加新函数.jQuery.fn.extend(object) 扩展 jQuery 元素集来提供新的方法 ...

  2. 【leetcode 简单】 第七题 合并两个有序链表

    将两个有序链表合并为一个新的有序链表并返回.新链表是通过拼接给定的两个链表的所有节点组成的. 示例: 输入:1->2->4, 1->3->4 输出:1->1->2- ...

  3. Kali设置代理

    原文:Kali-linux设置ProxyChains ProxyChains是Linux和其他Unices下的代理工具.它可以使任何程序通过代理上网,允许TCP和DNS通过代理隧道,支持HTTP.SO ...

  4. python之yagmail库笔记

    1. yagmail是啥 yagmail是给正常人用的,封装的比较彻底的一个python邮件库,发送接收邮件只需要几行代码,炒鸡简单. 2. 安装 使用pip安装,炒鸡简单: pip install ...

  5. 贪心算法_01背包问题_Java实现

    原文地址:http://blog.csdn.net/ljmingcom304/article/details/50310789 本文出自:[梁敬明的博客] 1.贪心算法 什么是贪心算法?是指在对问题进 ...

  6. 南邮综合题writeup

    http://teamxlc.sinaapp.com/web3/b0b0ad119f425408fc3d45253137d33d/index.php fuckjs直接console得到地址 http: ...

  7. NuGet Package Explorer上传时报:failed to process request:'Method Not Allowed'错误解决办法

    相关日志:PUT /api/v2/package - 1000 -  NuGet+Package+Explorer/3.15.0.0+(Microsoft+Windows+NT+6.2.9200.0) ...

  8. weblogic12.1.3 静默安装 建域

    --安装依赖包 yum -y install compat-libcap1 compat-libstdc++ gcc gcc-c++ glibc-devel libaio-devel libstdc+ ...

  9. 生成器(generator)和迭代(iterable , iterator, iteration)

    在搞清楚Generator之前,我们先讨论一下 iterable , iterator, iteration 1.Iterable 我们知道,在Python中所有东西都是object, 比如说变量,容 ...

  10. angular中使用AMEXIO

    1.用NPM添加依赖到项目中,amexio需要先添加以下四个依赖到项目 npm install jquery@3.2.1  --save npm install bootstrap@4.0.0-alp ...