コード例 #1
0
TreeNode *getLCA(TreeNode *node1, TreeNode *node2) {
    if (!node1 || !node2)
        return NULL;
    
    int len1 = getPathLen(node1);
    int len2 = getPathLen(node2);
    int cnt;
    if (len1 > len2)
    {
        cnt = len1 - len2;
        while (cnt--)
            node1 = node1->parent;
    }
    else if (len1 < len2)
    {
        cnt = len2 - len1;
        while (cnt--)
            node2 = node2->parent;
    }
    while (node1 != node2)
    {
        node1 = node1->parent;
        node2 = node2->parent;
    }
    return node1;
}
コード例 #2
0
ファイル: direntry.c プロジェクト: BiancoZandbergen/RTMINIX3
char *getPwd(direntry_t *entry)
{
	int size;
	char *ret;

	size = getPathLen(entry);
	ret = malloc(size+1);
	if(!ret)
		return 0;
	sprintPwd(entry, ret);
	return ret;
}
コード例 #3
0
ファイル: WebServer.cpp プロジェクト: pilate/esp32-snippets
/**
 * @brief Return the constituent parts of the path.
 * If we imagine a path as composed of parts separated by slashes, then this function
 * returns a vector composed of the parts.  For example:
 *
 * ```
 * /x/y/z
 * ```
 * will break out to:
 *
 * ```
 * path[0] = ""
 * path[1] = "x"
 * path[2] = "y"
 * path[3] = "z"
 * ```
 *
 * @return A vector of the constituent parts of the path.
 */
std::vector<std::string> WebServer::HTTPRequest::pathSplit() const {
	std::istringstream stream(std::string(getPath(), getPathLen())); // I don't know if there's a better istringstream constructor for this
	std::vector<std::string> ret;
	std::string pathPart;
	while (std::getline(stream, pathPart, '/')) {
		ret.push_back(pathPart);
	}
	// Debug
	for (int i = 0; i < ret.size(); i++) {
		ESP_LOGD(LOG_TAG, "part[%d]: %s", i, ret[i].c_str());
	}
	return ret;
} // pathSplit