Summary Ranges

Given a sorted integer array without duplicates, return the summary of its ranges.

For example, given [0,1,2,4,5,7], return ["0->2","4->5","7"].

class Solution {
public:
    string format(int begin, int end)
    {
        char buffer[32];
        if (end == begin)
        {
            sprintf(buffer, "%d", begin);
        }else{
            sprintf(buffer, "%d->%d", begin, end);
        }
        return string(buffer);
    }
    vector<string> summaryRanges(vector<int>& nums)
    {
        if(nums.size() == 0)
        {
            return vector<string>();
        }
        vector<string> svec;
        int start = 0;
        int end = 0;
        string tmp = "";
        /*if(nums.size() == 1)
        {
            svec.push_back(format(nums[0], nums[0]));
            return svec;
        }*/
        for(int i = 1; i < nums.size(); ++i)
        {
            if((nums[i] - nums[i - 1]) != 1)
            {
                tmp = format(nums[start], nums[i - 1]);
                svec.push_back(tmp);
                start = i;
                tmp = "";
            }
        }
        svec.push_back(format(nums[start], nums[nums.size() - 1]));
        return svec;   
    }
};


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Keras is an open-source neural network library written in Python. It is designed to enable fast experimentation with deep neural networks and easy deployment to production. Keras provides a high-level API for building and training deep learning models. The Keras summary method is used to provide a summary of the model architecture, including the number of parameters and the output shape of each layer. This summary can be useful for debugging and optimizing the model, as well as understanding its structure and behavior. The Keras summary method takes an optional argument called "line_length," which specifies the maximum length of each line in the summary output. If the line length is too short, the summary may be split across multiple lines, making it difficult to read. If the line length is too long, the summary may become too wide to fit on the screen. To use the Keras summary method, first create a Keras model by defining its layers and compiling it with an optimizer and loss function. Then, call the summary method on the model object: ``` from keras.models import Sequential from keras.layers import Dense # Define a simple Keras model model = Sequential() model.add(Dense(64, activation='relu', input_dim=100)) model.add(Dense(1, activation='sigmoid')) # Compile the model with an optimizer and loss function model.compile(optimizer='rmsprop', loss='binary_crossentropy', metrics=['accuracy']) # Print a summary of the model architecture model.summary() ``` The output of the summary method will look something like this: ``` Model: "sequential_1" _________________________________________________________________ Layer (type) Output Shape Param # ================================================================= dense_1 (Dense) (None, 64) 6464 _________________________________________________________________ dense_2 (Dense) (None, 1) 65 ================================================================= Total params: 6,529 Trainable params: 6,529 Non-trainable params: 0 _________________________________________________________________ ``` This summary shows that the model has two layers, one with 64 neurons and one with 1 neuron, and a total of 6,529 parameters. It also shows the output shape of each layer, which is (None, 64) for the first layer and (None, 1) for the second layer. Finally, it shows the total number of trainable parameters and non-trainable parameters in the model.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值